Skip to content

Instantly share code, notes, and snippets.

@AkashRajvanshi
Created November 2, 2019 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkashRajvanshi/d9c296f16a50e715ee4395d405f69bf6 to your computer and use it in GitHub Desktop.
Save AkashRajvanshi/d9c296f16a50e715ee4395d405f69bf6 to your computer and use it in GitHub Desktop.
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