I have a JavaScript object array. When write console.log(myarry)
it will show in the console in the below form.
Array[2]
0: Object
one: \"one\"
Use for-loop
instead of for-in
to iterate array.
Use Object.keys to get keys of object
var arr = [{
one: 'one'
}, {
two: 'two'
}];
for (var i = 0, l = arr.length; i < l; i++) {
var keys = Object.keys(arr[i]);
for (var j = 0, k = keys.length; j < k; j++) {
console.log("Key:" + keys[j] + " Value:" + arr[i][keys[j]]);
}
}