Skip to content

Instantly share code, notes, and snippets.

@DraCaster
Created August 27, 2021 01:57
Show Gist options
  • Save DraCaster/c57c4d35f0830fa5252de2ddac9cdddc to your computer and use it in GitHub Desktop.
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?
/** 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