Last active
November 20, 2019 21:11
Iterating Over Object Entries in JS using Object.values : 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.values(obj).forEach(value => { | |
//use value here | |
}); | |
//traditional for loop | |
let values = Object.values(obj); | |
for(let i = 0; i<values.length;i++){ | |
let value = values[i]; | |
} |
Use Object.values(obj).map instead.
Object.values(obj).map(value => { return <h2> {value.name} </h2> });
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Object.values(obj).forEach(value => {
console.log(value.name)
});
it works fine and all the name are display in console but when use it in react and want these names on screan but it do nothing code is like below
Object.values(obj).forEach(value => {
h2 {value.name} /h2
});