I want to compare two arrays and return a new array with any items only found in one of the two given arrays, but not both
This is my code :
function diffArray(arr1, arr2) {
var newArr = [];
for(var i =0; i <arr1.length ; i++){
if(arr2.indexOf(arr1[i]) < 0){
newArr.push(arr1[i]);
}
}
for(var j =0; j <arr2.length ; j++){
if(newArr.includes(arr2[i]) !== true){
if(arr1.indexOf(arr2[i])<0){
newArr.push(arr2[i])
}
}
}
return newArr;
}
its not working right. newArr after first for loop is empty , i cant get where i am wrong .. thank you in advance for any idea