Tuesday, 16 May 2017

javascript - Iterate through object properties



var obj = {
name: "Simon",

age: "20",
clothing: {
style: "simple",
hipster: false
}
}

for(var propt in obj){
console.log(propt + ': ' + obj[propt]);
}






How does the variable propt represent the properties of the object? It's not a built-in method or property. Why does it come up with every property in the object?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...