Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add property and copy array of objects into an nested objects

I would like to copy an array of objects in a nested object with new property. How can I use es6 to achieve something like this

I would like to copy:

['cat', 'Dog', 'monkey'] into

[{"text":"cat"},{"text":"Dog","extraClasses":["ti-extra"]}, {"text":"monkey"}]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Maybe function like this where getClasses function returns classes array.

['cat', 'Dog', 'monkey'].map((item) => {
  return { text: item, extraClasses: getClasses() };
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading