Reputation: 23
Currently this is my code for getting the key that I want from my Object:
for (let [key, value] of Object.entries(d)) {
if (key == input){
//do something
}
}
Is there a faster way to get that key without iterating through every entry? Thank you
Upvotes: 0
Views: 56
Reputation: 26
Find will find and return first element founded, so theoretically if you element lays first it will be blazing fast
Object.keys(obj).find(key => obj[key] === value)
Upvotes: 0