Diff of Two arrays

Tell us what’s happening:
I can seem to get desired output. Someone help

Your code so far

function diffArray(arr1, arr2) {
var newArr = ;
for(let i=0;i<arr1.length;i++){
if(arr2.indexOf(arr1[i])<0){
newArr.push(arr2[i])
}
}
return newArr;
}

console.log(diffArray([1,2,3,5], [1, 2, 3, 4, 5]));


function diffArray(arr1, arr2) {
var newArr = [];
for(let i=0;i<arr1.length;i++){
  if(arr2.indexOf(arr1[i])<0){
  newArr.push(arr2[i])
  }
}
return newArr;
}

console.log(diffArray([1,2,3,5], [1, 2, 3, 4, 5]));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Diff Two Arrays

Link to the challenge:

you are getting the elements of arr1 that are not present in arr2, but what about the elements in arr2 that are not present in arr1?


this is not a correction, just a suggestion
instead of indexOf you can think of using includes, as you don’t actually need to know the position of the elements