So, I have an associative array and the keys in the array are properties of an object. I want to loop through the array and in each interation do something like this:
Object.key
This however does not work and results in returning undefined rather than the value of the property.
Is there a way to do this?
You can use a for ... in loop:
for (var key in obj) {
//key is a string containing the property name.
if (!obj.hasOwnProperty(key)) continue; //Skip properties inherited from the prototype
var value = obj[key];
}
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