I need to find all objects of array, which contain color "green" in "mode" property.
let arr = [
{
"type": "One",
"mode": [{
"color": "blue",
"size": "L"
}
]
}, {
"type": "Two",
"mode": [{
"color": "green",
"size": "M"
}
]
},{
"type": "Three",
"mode": [{
"color": "green",
"size": "L"
}
]
},{
"type": "Four",
"mode": [{
"color": "red",
"size": "XS"
}
]
}
];
let result = arr.indexOf(arr.find(function(el,index){
return el['mode'][0].color === 'green';
}))
console.log(result);
Currently I can only get the index.
I would like to get something like this in the output:
[
{
"type": "Two",
"mode": [{
"color": "green",
"size": "M"
}
]
},{
"type": "Three",
"mode": [{
"color": "green",
"size": "L"
}
]
}
]