I'm trying to filter objects in an array that contain specific values inside a property that is an array. Example, here is my array of objects:
[
{_id: 1, value: ['Row', 'Column']},
{_id: 2, value: []},
{_id: 3, value: ['Row']},
{_id: 4},
{_id: 5, value: ['Column']}
]
I need it to return all objects with 'Row' in the value array, i.e. the result should be:
[
{_id: 1, value: ['Row', 'Column']},
{_id: 3, value: ['Row']},
]
Here's my method to do this but it's returning null:
findRowValues() {
let groupObj = [
{_id: 1, value: ['Row', 'Column']},
{_id: 2, value: []},
{_id: 3, value: ['Row']},
{_id: 4},
{_id: 5, value: ['Column']}
];
return groupObj.filter(function (obj) {
return (
obj.value &&
obj.value.find(o => { o === 'Row' })
)
});
}