I have an array of object b
and an array a
. I would like to filter b
to only have objects where the to
values are in a
. I've tried many ways but I always receive an empty array. For example this case, the final result would be an array with the first and the second object from the array but not the last one.
const a = [
"dfd302f4-571b-42da-9b35-07d1d9b6e68d",
"d7099abd-6872-48db-bdd7-ca99e4513586",
"93272093-5089-40cd-8c3d-2412377e1f32"
];
const b = [
{
name: "toto",
to: [
"d7099abd-6872-48db-bdd7-ca99e4513586",
"93272093-5089-40cd-8c3d-2412377e1f32"
]
},
{ name: "tota", to: ["dfd302f4-571b-42da-9b35-07d1d9b6e68d"] },
{ name: "tota", to: ["8418v4rfe484evf48ez64vrfe6zv4r8ezvf4"] }
];
console.log(b.filter(user => a.includes(user.to)))