✅ – shuntera12 – 23-03 Nov 9

Hey everyone! How to add a property to object after a particular property? Like if const obj = { a:"Name", b:"Rohit", age:12, } and i want to add the property after b, can anyone help me with this?
S
shuntera12524d ago
so in my case there are thousand objects with different structure but same property names, and I want to add a new property after a particular property, how will I do so?
S
S3BAS524d ago
You should not use an object if you want a specific order You should use an array instead What's the use case here? @shuntera12
S
shuntera12524d ago
I am using Prismic (CMS) and I want to change the data of the CMS, since there is no write API, I would need to manually upload JSON files to the CMS. Now, the CMS will only work if the imported json file is in correct order/structure. Therfore, i want to add new properties in json file at the correct order @S3BAS
S
S3BAS524d ago
Now, the CMS will only work if the imported json file is in correct order
Are you really, really sure about this? I highly doubt that's a requirement
S
shuntera12524d ago
Lemme checkkk There's nothing mentioned in the docs about the structure, but my senior told me that the structure should remain the same @S3BAS what should I do now? 😓
S
S3BAS524d ago
The structure in terms of keys/values being present sure But the order should not matter
S
shuntera12524d ago
so can I proceed with adding properties at random order, right?
S
S3BAS524d ago
Have you tried it out? :p (but yes, very likely)
S
shuntera12524d ago
I don't have access to upload, only thing I can provide my manager is my json file
S
S3BAS524d ago
Ah, but yeah the order of the keys in the object should not matter
S
shuntera12524d ago
yep, thanks for clarifying 💯
S
S3BAS524d ago
meowthumbsup
UU
Unknown User524d ago