I am using the forEach() on the array that is passed through. The function I am passing into forEach() is if the element of arrays
does not match with one of the arguments given, then push it into the newArray
.
However, I keep getting a blank array, when I want to see newArray = [1, 2]
.
I am thinking there is something wrong with my if statement, but I really don't see what the problem is. I can't seem to put a finger on the issue.
const removeFromArray = function(arrays, ...args) {
const newArray = [];
for (const arg of args) {
if (arrays.forEach((element) => element !== arg))
newArray.push(element);
}
return newArray;
}
removeFromArray([1,2,3], 3);