Question

So there is a javascript object like

1
2
3
4
5
var objects = {
type:"Fiat",
model:"500",
color:"white"
}

If the key names are random, and we don’t know. How to get each property’s value with a loop?

Answer

By using for..in.. loop:

1
2
3
for(var key in objects) {
var value = objects[key];
}

Reference


This is the end of post