I have an object with some propreties:
const carOptions = {
mazda: 25000,
tesla: 85000,
bmw: 100000
}
I would like to convert a for
loop …
for (let i = 0; i < cars.length; i++) {
if (cars[i].checked) {
return carOptions[cars[i].id]
}
}
…
… To .forEach
but this code isn't working:
cars.forEach(function(cars)) {
if (cars.checked) {
return carOptions[cars.id]
}
}
…
What am I missing?