/ JAVASCRIPT, FRONT-END

How to get properties values of a object without knowing their keys in Javascript?

Question

So there is a javascript object like

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:

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

Reference


This is the end of post