Skip to content

Instantly share code, notes, and snippets.

@chathurawidanage
Last active December 1, 2020 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chathurawidanage/f1ee768770050054fb1943b773f9e449 to your computer and use it in GitHub Desktop.
Save chathurawidanage/f1ee768770050054fb1943b773f9e449 to your computer and use it in GitHub Desktop.
Iterating Over Object Entries in JS using for...in | Performance Comparison [https://gists.cwidanage.com/2018/06/how-to-iterate-over-object-entries-in.html]
let obj = {
key1: "value1",
key2: "value2",
key3: "value3"
}
for (const key in obj) {
let value = obj[key];
//optional check for properties from prototype chain
if (obj.hasOwnProperty(key)) {
//no a property from prototype chain
}else{
//property from protytpe chain
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment