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.
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.
This should help:
const car = [{id: "1", brand: "Opel"}, {id: "2", brand: "Haima"},{id: "3", brand: "Toyota"}];
const brands = car.map(({ brand }) => brand);
You can use array map to return all brands. Look at the following use of map.
car.map(o => o.brand)