Reputation: 83
I have an array of 10 users, I want to filter the users based on the 'intresses' (that means interests in dutch) array within the users. So for example I want to filter all the users that have the interests 'Afrika' (like index 2).
This is what I tried but it will give me an empty array back.
var newArray = gesorteerdeMatchPercentages.filter((el) => {
el.intresses.forEach((item) => {
return item.naam === "Afrika";
});
});
console.log("new", newArray);
Upvotes: 0
Views: 54
Reputation: 6269
If i understand you correctly you could do that using Array.prototype.some()
like this
var newArray = gesorteerdeMatchPercentages.filter((el) => {
return el.intresses.some(el => el.naam === 'Afrika');
});
Upvotes: 1