Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const properties = Object.keys(user);
// length = len
let i, len;
for (i=0, len=properties.length; i<len; i++) {
console.log("Name: " + properties[i]); // Name: firstName, Name: showDetails
console.log("Value: " + user[properties[i]]); // Value: Akash, Value: function ()
}
console.log(properties) // [ 'firstName', 'showDetails' ]
// Custom Property in user
console.log("firstName" in user); // true
console.log(user.propertyIsEnumerable("firstName")) // true (because it is listed in Object.keys())
// Inherited Property
console.log("length" in properties); // true
console.log(properties.propertyIsEnumerable("length")) // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.