Reputation: 1227
I have a 2 arrays i need to show only data which match with first array.
Example
first array is like
["1", "2" , "3"]
second is like
[{"name": "xyz", "id": "1"},{"name":"abc", "id": "3"}, ,{"name":"def", "id": "4"}]
result
[{"name": "xyz", "id": "1"},{"name":"abc", "id": "3"}}
I try like this but showing empty Array
console.log(this.secondArr.filter(d => d.id === firstArr));
Upvotes: 1
Views: 105
Reputation: 5418
You need to compare it with each entry in the array, not the array itself:
this.secondArr.filter(d => firstArray.some(arrEntry => arrEntry === d.id))
Upvotes: 5