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

How to parse an array of objects to a list of strings? (Javascript)

In my Vue application I have a list of objects looking like this:

const arr = [ { id: 1, name: 'Max', grade: 3 }, { id: 2, name: 'Lisa', grade: 2 } ];

Now I want every Object in this array to be a single string for itself. I know there is JSON.stringifty but this makes my whole array to a string and not every single object.

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

So the result should be something like:

const arr = ["{id:1,name:'Max',grade:3}", "{id:2,name:'Max',grade:3}"]

>Solution :

That would be

const myJsonArr = arr.map((v) => JSON.stringify(v))
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