Make an array of an objects Keys.
Object.keys
- Creates an array
of keys from an object
passed in.
const fruit = {
apples: 5,
oranges: 10,
lemon: 7,
grapes: 3,
}
const fruitKeys = Object.keys(fruit)
// [ 'apples', 'oranges', 'lemon', 'grapes' ]
Make an array of an objects values
Object.values
- Creates an array
from the values from an object
passed in.
const fruit = {
apples: 5,
oranges: 10,
lemon: 7,
grapes: 3,
}
const fruitValues = Object.values(fruit)
// [ 5, 10, 7, 3 ]
Make an array from an array keys and values
Object.entries
- Creates an array
from the keys and values from an object
passed in.
const fruit = {
apples: 5,
oranges: 10,
lemon: 7,
grapes: 3,
}
const fruitEntries = Object.entries(fruit)
/* [ [ 'apples', 5 ],
[ 'oranges', 10 ],
[ 'lemon', 7 ],
[ 'grapes', 3 ] ] */
Top comments (0)