I have an array of objects, and I want to find property 'plane: true' in some objects and set it to false. And it just adds to array on the same area as an objects. I tried to use function of angular forEach() but nothing happened. Help please.
this.typeTransport = [
{
currentTransport: 'plane',
changeTransport: 'plane_disable',
plane: true
},
{
currentTransport: 'train',
changeTransport: 'train_disable',
train: true
},
{
currentTransport: 'bus',
changeTransport: 'bus_disable',
bus: true
},
{
currentTransport: 'ship',
changeTransport: 'ship_disable',
ship: true
}
];
angular.forEach(this.typeTransport, function(value, key){
angular.forEach(value, function(value, key){
if(key === 'plane'){
this.typeTransport[key] == false ? this.typeTransport[key] = true : this.typeTransport[key] = false;
console.log(this.typeTransport);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>