I have an object in javascript
var o = [
{city: 'armenia', population: 300000},
{city: 'russia', population: 1200000}
];
I need to loop through it; please help
I have an object in javascript
var o = [
{city: 'armenia', population: 300000},
{city: 'russia', population: 1200000}
];
I need to loop through it; please help
This question been answered before. Needless to say loop thru the array using the length property and loop thru the object using a foreach
loop. for each...in
for (var i = 0; i < o.length; i++) {
var obj = o[i];
for (var key in obj) {
// key
console.log(key);
// value
console.log(obj[key]);
}
}