Created
November 1, 2019 10:32
-
-
Save gil00pita/d35ebe36d7aa091fcb02bae7319cb3eb to your computer and use it in GitHub Desktop.
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
const array = [ | |
[ 'one', 1 ], | |
[ 'two', 2 ] | |
]; | |
Object.fromEntries(array); | |
// { one: 1, two: 2 } |
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
const zoo = { | |
lion: '🦁', | |
panda: '🐼' | |
}; | |
Object.keys(zoo) | |
// ['lion', 'panda'] | |
Object.values(zoo) | |
// ['🦁', '🐼'] | |
Object.entries(zoo) | |
// [ ['lion', '🦁'], ['panda', '🐼'] ] |
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
var numbers = { | |
one: 1, | |
two: 2 | |
}; | |
var keys = []; | |
for (var number in numbers) { | |
if(numbers.hasOwnProperty(number)){ | |
keys.push(number) | |
} | |
} | |
keys; // [ 'one', 'two' ] | |
Object.keys(numbers); | |
// [ 'one', 'two' ] | |
Object.values(numbers); | |
// [ 1, 2 ] | |
Object.entries(numbers); | |
// [ ['one', 1], ['two', 2] ] |
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
const numbers = { | |
one: 1, | |
} | |
const objectArray = Object.entries(numbers); | |
objectArray.forEach(([key, value]) => { | |
console.log(key); // 'one' | |
console.log(value); // 1 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment