JS: List all properties and values of an object

 If you need to generate forms dynamically to update some JS objects for instance:

var obj = {prop1: 5, prop2: 13, prop3: 8};
var keys = Object.keys(obj);

var key;
var value;
for (var i=0; i<keys.length; i++){
    key = keys[i];
    value = obj[key];

    console.log(key);
    console.log(value);
}

Advertisements