Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of a key from a dictionary array JavaScript [duplicate]

so in Javascript I have an array structured like this:

car = [{id: "1", brand: "Opel"}, {id: "2", brand: "Haima"},{id: "3", brand: "Toyota"}]

How can I get the values of all the brands only.

like image 566
Divine Grace Adriano Avatar asked Jun 10 '26 02:06

Divine Grace Adriano


2 Answers

This should help:

const car = [{id: "1", brand: "Opel"}, {id: "2", brand: "Haima"},{id: "3", brand: "Toyota"}];

const brands = car.map(({ brand }) => brand);
like image 123
Juan Elfers Avatar answered Jun 11 '26 16:06

Juan Elfers


You can use array map to return all brands. Look at the following use of map.

car.map(o => o.brand)
like image 43
Shubham Gupta Avatar answered Jun 11 '26 16:06

Shubham Gupta