shuntera12
shuntera122y ago

✅ – 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?
14 Replies
shuntera12
shuntera122y 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?
S3BAS
S3BAS2y 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
shuntera12
shuntera122y 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
S3BAS
S3BAS2y 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
shuntera12
shuntera122y 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? 😓
S3BAS
S3BAS2y ago
The structure in terms of keys/values being present sure But the order should not matter
shuntera12
shuntera122y ago
so can I proceed with adding properties at random order, right?
S3BAS
S3BAS2y ago
Have you tried it out? :p (but yes, very likely)
shuntera12
shuntera122y ago
I don't have access to upload, only thing I can provide my manager is my json file
S3BAS
S3BAS2y ago
Ah, but yeah the order of the keys in the object should not matter
shuntera12
shuntera122y ago
yep, thanks for clarifying 💯
S3BAS
S3BAS2y ago
meowthumbsup
reactibot
reactibot2y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1040038858521317416
reactibot
reactibot2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1040038858521317416 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26