Browse By

How to loop through javascript object. The easy way!

Under ECMAScript 5, you can combine Object.keys() and Array.prototype.forEach()

var obj = { first: "Chris", second: "Maria", third: "Alex" };
Object.keys(obj).forEach(function(key) { console.log(key, obj[key]); });

More details: Object.keysArray.prototype.forEach.

Leave a Reply

Your email address will not be published. Required fields are marked *