I have 2 arrays:
[
{
"id": 1,
"name": "All",
},
{
"id": 2,
"name": "APR",
},
{
"id": 3,
"name": "TER",
}]
The second array is ["APR", "TER"]
I want to filter the first array with the second that is the output should be
[{
"id": 2,
"name": "APR",
},{
"id": 3,
"name": "TER",
}]
Trying this with filter function - is that possible?
Thanks Anand
Pretty standard use of the filter method. Just give it the right condition to check, and you're good to go:
const myArray = [{
"id": 1,
"name": "All",
}, {
"id": 2,
"name": "APR",
}, {
"id": 3,
"name": "TER",
}];
const otherArray = [
"APR",
"TER",
];
const filtered = myArray.filter(x => otherArray.includes(x.name));
console.log(filtered)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments