Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filtering an array from another array in vue

This might be something really simple, but I just can’t figure it out. What I’m trying to do is take 2 arrays and filter out what I don’t need and only
return the one array.

So what I have right now is this

let array1 = [1, 2, 3];
let array2 = [1, 2, 3, 4, 5, 6];

and what I would like is to return array 2 with only the items that doesn’t show up in array1 so that would be 4, 5,6.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is what I have so far


return array1.forEach(a => {
    array2.filter(aa => aa !== a)
});

and that doesn’t return anything

>Solution :

let array1 = [1, 2, 3];
let array2 = [1, 2, 3, 4, 5, 6];

let array3 = array2.filter(i => !array1.includes(i));

console.log(array3)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading