I’m trying to build a function that removes an item from an array. Both the array and item are configured using parameters pushing in when I call the function.
However it’s not returning the expected [1,2,4] rather it’s returning “not yet” a string I built into an if statment to return if it fails.
I can see in a console log the popped variable = 3 and the current for loop is correctly looping through all the options. So why isn’t it working?
const removeFromArray = function() {
let args = Array.from(arguments);
let popped = args.pop();
for (i = 0; i < args.length; i++) {
let current = args[i];
if (current === popped) {
console.log(args);
return args;
} else {
console.log("not yet");
}
}
};
removeFromArray([1, 2, 3, 4], 3);