Skip to content

Instantly share code, notes, and snippets.

@salmanx
Created April 10, 2021 14:33
Show Gist options
  • Save salmanx/3cebea2f675e73b587e3073d1a58c9a6 to your computer and use it in GitHub Desktop.
Save salmanx/3cebea2f675e73b587e3073d1a58c9a6 to your computer and use it in GitHub Desktop.
.map() also has a substitute that we can use which is .from()
let cars = [
{
"color": "purple",
"type": "minivan",
"registration": new Date('2017-01-03'),
"capacity": 7
},
{
"color": "red",
"type": "station wagon",
"registration": new Date('2018-03-03'),
"capacity": 5
}
]
// map:
cars.map(c => c.color)
(2) ["purple", "red"]
// Array.from() //
Array.from(cars, ({color}) => color)
(2) ["purple", "red"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment