1

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.

This is what I have so far


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

and that doesn't return anything

2 Answers 2

1

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

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

console.log(array3)

Sign up to request clarification or add additional context in comments.

Comments

0

This might help to solve your problem.

 let array1 = [1, 2, 3]
    let array2 = [1, 2, 3, 4, 5, 6]
    function returnList(arOne,arTwo){
      return arTwo.filter(a => !arOne.includes(a))
    }
    let response = returnList(array1 ,array2 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.