If I have a javascript object like this :
data = {
a : 2,
b : 3
}
but a and b are arbitrary and decided at runtime. Is there any way to go through the object
and access all properties without knowing the key?
Answer
data = {
a : 2,
b : 3
}
for(var propName in data) {
if(data.hasOwnProperty(propName)) {
var propValue = data[propName];
// do something with each element here
}
}
No comments:
Post a Comment