I have two a
var statusFilter = [
{label: '1', checked: false},
{label: '3', checked: false},
{label: '4', checked: false},
{label: '5', checked: false},
];
var activeStatusFilter = [
{label: '1', checked: true},
{label: '2', checked: true},
];
I need to filter out activeStatusFilter such that any element in activeStatusFilter not present in statusFilter should be removed. So the result of the function should be [{label: '1', checked: true}] because label: '2' is not present in status filter.
I have written a function to do the same but it always return an empty array.
const z = activeStatusFilter.filter( activeStatus =>
{
let found = false;
statusFilter.forEach(status => {
console.log( activeStatus );
console.log( "status", status )
found = ( activeStatus.label === status.label )
return found
})
return found;
} )
I feel that in the forEach when found = ( activeStatus.label === status.label )
it should return from the forEach but it does not. Can someone help me in why this is not returning or a more optimised approach