I'm tackling a challenge to create a custom function that can remove specified arguments from an array. While the concept is clear, my current implementation isn't quite hitting the mark yet.
For instance, if given the array [1,2,3,4]
and the argument 2,3
, the expected output should be [1,4]
.
Here's what I've got in place:
const removeFromArray = (arr) => {
let args = Array.from(arguments);
return arr.filter(function (item) {
!args.includes(item);
});
}
Despite efforts, it falls short when trying to remove specific items from the array, only working with all elements removed instead.
Looking for guidance on how to modify this approach so that it successfully handles scenarios where the provided argument doesn't exist in the array (thus ignoring it), as well as situations involving string values within the array.
Your support is greatly appreciated!