Created
August 27, 2021 01:57
-
-
Save DraCaster/c57c4d35f0830fa5252de2ddac9cdddc to your computer and use it in GitHub Desktop.
What is the best way to get the key of key/value javascript object?
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
/** There are many roads, these are some of them... :) **/ | |
const myObject = {name: 'Lujan', nickname: 'Lushan'} | |
for(let key in myObject){ | |
console.log(`Key: ${key}`); | |
console.log(`Keys value ${myObject[key]}`); | |
} | |
//Or | |
Object.keys(myObject) | |
.forEach(function eachKey(key) { | |
console.log(`Key: ${key}`); | |
console.log(`Keys value ${myObject[key]}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment