Skip to content

Instantly share code, notes, and snippets.

@gil00pita
Created November 1, 2019 10:32
Show Gist options
  • Save gil00pita/d35ebe36d7aa091fcb02bae7319cb3eb to your computer and use it in GitHub Desktop.
Save gil00pita/d35ebe36d7aa091fcb02bae7319cb3eb to your computer and use it in GitHub Desktop.
const array = [
[ 'one', 1 ],
[ 'two', 2 ]
];
Object.fromEntries(array);
// { one: 1, two: 2 }
const zoo = {
lion: '🦁',
panda: '🐼'
};
Object.keys(zoo)
// ['lion', 'panda']
Object.values(zoo)
// ['🦁', '🐼']
Object.entries(zoo)
// [ ['lion', '🦁'], ['panda', '🐼'] ]
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] ]
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