This is my function
const filterPerBlocked = (showBlocked) => {
const filtered_copy = [];
filtered.forEach( (element) => {
let composites_copy = element.composites.filter( (composite) => {
composite.blocked == showBlocked
})
filtered_copy.push({
category: _.cloneDeep(element.category),
composites: composites_copy
})
});
console.log(filtered_copy);
}
Some elements inside the filter are giving true result on composite.blocked == showBlocked but composites_copy its always empty, shouldn't composites_copy contain the filtered result?
filteredarray looks like?return composite.blocked == showBlocked..filter()requires you to return true or a true-ty value for the items you want to keep. Since you do not return anything inside the filter function, your array always ends up empty. And you are not using a one-liner arrow function, since you use braces around the function body.=> { }. So trycomposite => composite.blocked === showBlockedwithout braces.(composite) => (composite.blocked == showBlocked)