我有一个数组。我遍历该数组。如何将当前值用作for循环内map函数内的属性?
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>
如您所见,在执行的map函数中,我使用了.item,并且{{item}}应该来自父循环。这里的项目应指“汽车”
请咨询。