I want to implement a function that takes an array and some other arguments then removes the other arguments from that array. So i used the rest parameter for the second argument then used Array.from to convert it an array, then used .length to get its length to use it as the second parameter for splice and it doesn't works. I know there are better ways to solve this problem, but I want to why it's not working .
const removeFromArray = function(array, ...number) {
let numArray = Array.from(number)
for(let i = 0; i < array.length ; i++ ){
if(number == array[i]){
array.splice( i , numArray.length);
}
}
return array;
};
removeFromArray([2, 1, 2, 3, 4], 1, 2);
expecting the output to be: [3, 4]
but it's: [2, 1, 2, 3, 4]
const removeFromArray = function(array, ...numbers) { let numArray = Array.from(numbers);
};
console.log(removeFromArray([2, 1, 2, 3, 4], 1, 2));