I have an array of objects:
a = [
{81.25: {p:81.25}},
{81.26: {p:81.26}}
]
I want to loop through array ang get value of p in each element:
for (var key in a) {
console.log(a[key]); // outputs {81.25: Object}
//How do i get p value out of the current element?
}
EDIT: sorry for misleading, I wodnt want to loop againg - thought may be some way to get first object inside current one and to get it's property p.
Use a standard for
loop for the array:
for (var i = 0; i < a.length; i++) {
if (typeof a[i] == object) { //object test
for (var key in a[i]) {
if (a[i].hasOwnProperty(key)) {
console.log(a[i][key]); //here ya go
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With