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.

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))

Leave a Reply