I have the following forEach loop over a JSON object called obj:
forEach
obj
Object.keys(obj).forEach(function(){});
How can I make it console.log both key and value of each item inside the object?
console.log
key
value
Something like this:
Object.keys(obj).forEach(function(k, v){ console.log(k + ' - ' + v); });
Use index notation with the key.
Object.keys(obj).forEach(function(k){ console.log(k + ' - ' + obj[k]); });
1.4m articles
1.4m replys
5 comments
57.0k users