I want to traverse through JavaScript object\'s property
var obj =
{
a: \'value1\',
b: \'value2\',
c: \'value3\',
d: \'va
If you're in an ES6 friendly environment, you can also try using the for...of loop which is closer to your original attempt.
EDIT: As Caleb pointed out, for..of
is specific to collections with the Symbol.iterator property (e.g. not standard JS objects).
But I'm leaving this answer here in case anybody else finds it useful at some point to have it pointed out explicitly that a for..of
is not a great solution here.
let obj = {};
for (let prop of obj) { // This will throw an error
prop = 'xxx';
}
Reference: MDN - for...of