Getting the object's property name Getting the object's property name javascript javascript

Getting the object's property name


i is the name.

for(var name in obj) {    alert(name);    var value = obj[name];    alert(value);}

So you could do:

seperateObj[i] = myObject[i];


Use Object.keys():

var myObject = { a: 'c', b: 'a', c: 'b' };var keyNames = Object.keys(myObject);console.log(keyNames); // Outputs ["a","b","c"]