Last active
November 20, 2019 21:12
-
-
Save chathurawidanage/f0b4b14af8966d8180d3708322fedf63 to your computer and use it in GitHub Desktop.
Iterating Over Object Entries in JS using Object.keys | Performance Comparison [https://gists.cwidanage.com/2018/06/how-to-iterate-over-object-entries-in.html]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let obj = { | |
key1: "value1", | |
key2: "value2", | |
key3: "value3" | |
} | |
//convinient forEach | |
Object.keys(obj).forEach(key => { | |
let value = obj[key]; | |
//use key and value here | |
}); | |
//traditional for loop | |
let keys = Object.keys(obj); | |
for(let i = 0; i< keys.length;i++){ | |
let value = obj[keys[i]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment