So, How to Loop JavaScript Object Values ?
Here It's
const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
let text = "";
for (let x in myObj) {
text += myObj[x] + ", ";
}
Updated:
I find simple one line code for that without use loop from comment section.
const text = Object.values(myObj).join(',')
Comment By rancy98 , Thank you rancy
So Simple, Isn't it? Have a Nice day and Don't forget to follow.
Top comments (4)
You can highlight the code, by adding js after the openign code block, see the editor guide here
There is also a little sytax error:
Notice, you are doing
= +=
, it should be just+=
Have a nice day too!
Thank you for commenting about mistake ! I updated my post according to this.
const text = Object.values(myObj).join(', ')
Thank you !, I updated my post according to your comment