Getting the object’s property name

I was wondering if there was any way in JavaScript to loop through an object like so.

for(var i in myObject) {
    // ...
}

But get the name of each property like this.

for(var i in myObject) {
    separateObj[myObject[i].name] = myObject[i];
}

I can’t seem to find anything like it on Google. They say to pass the names of the variables with them but this is not an option for what I am trying to achieve.

Thanks for any help you can offer.

13 Answers
13

Leave a Comment