Skip to content

Instantly share code, notes, and snippets.

@chathurawidanage
Last active June 18, 2020 08:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurawidanage/6ae844557c8b40df3d1d7875abceecef to your computer and use it in GitHub Desktop.
Save chathurawidanage/6ae844557c8b40df3d1d7875abceecef to your computer and use it in GitHub Desktop.
Iterating Over Object Entries in JS using Object.entries | Performance Comparison [https://gists.cwidanage.com/2018/06/how-to-iterate-over-object-entries-in.html]
let obj = {
key1: "value1",
key2: "value2",
key3: "value3"
}
//convinient forEach
Object.entries(obj).forEach(entry => {
let key = entry[0];
let value = entry[1];
//use key and value here
});
//traditional for loop
let entries = Object.entries(obj);
for(let i = 0; i< entries.length;i++){
let key = entries[i][0];
let value = entries[i][1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment