I have an array. I loop over that array. How to use the current value as a property inside a map function inside a for loop?
var abc = ['FRUITS', 'COLORS', 'CARS', 'COMPUTERS'];
var cars = [{
name: "Saab",
CARS: 'Saab 9 -5'
}, {
name:"Volvo",
CARS: 'XC 60'
}, {
name: "BMW",
CARS: '5 Series'
}];
_.forEach(abc, (item, index) => {
if (item === 'CARS') {
var car = _.map(cars, (car) => {
return car.item
})
console.log(car)
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
As you see, in the map function I carry out, I use a .item and that {{item}} should be from the parent loop. Here item should refer to "CARS"
Please advice.