DEV Community

Discussion on: Help with includes() in js

Collapse
 
magimart profile image
Magima Felix O

i have to look into this approach, thank you very much for the response

Collapse
 
vonheikemen profile image
Heiker

Actually I was just trying to explain how Array.includes works.

What would solve your problem is to transform formB into an array of names before using formA.filter. Like this.

const formBNames = formB.map((x) => x.name);

const difference = formA.filter((x) => !formBNames.includes(x.name));
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
magimart profile image
Magima Felix O

thank your very much for your kind efforts, i tried it like you stated already but got got a desirable result. i used a set method instead and worked well.
Another contribute here also commented with reducer() that also works perfect :)