I have two arrays of objects, defined as following:
contacts array:
[
{ id: "1", name: "test"},
{ id: "2", name: "foo" },
{ id: "3", name: "june"},
{ id: "4", name: "may" }
]
filtered_contacts array:
[
{
id: "1",
options: [
{ option_id: "1", contact_linked_id: "2" },
{ option_id: "2", contact_linked_id: "4" },
]
},
{
id: "2",
options: [
{ option_id: "3", contact_linked_id: "1" },
]
},
]
I need to extract the contacts which are included in filtered_contacts with the contact_linked_id field, for doing so I wrote the following code:
var c = contacts.map(c => filtered_contacts.find(x => x.options.map(z => z.contact_linked_id == c.id)));
but the result is completely wrong, I get a lot of copies of the first contact : test.