I'm slowly learning JavaScript, and to this point I could figure everything out on my own. But I'm just spending waaay to much time at this problem.
Basically, I have two arrays, and if a number in the second array matches a number in the first array, it has to delete that number.
So the simplest solution I can think of is a for loop that loops through each property of the array, and if it doesn't match a number out of the second array, push it into a new array.
I have written this bit of code:
var arr = [1, 2, 3, 5, 1, 2, 3], newArr = [2, 3, 3];
var finalArr = [];
for (var i = 0; i < newArr.length; i++) {
if (arr[i] != newArr[0] && arr[i] != newArr[1] && arr[i] != newArr[2])
finalArr.push(arr[i]);
}
// ----> finalArr = [1]
The purpose is, it takes every value out of the array named "arr", compares it to a value of "newArr", and if the value doesn't match, push it into a new array.
Can anyone see the problem?
Thanks in advance!