I need to write a function that will delete the number or item entered in the input box. Heres what I have so far...
const my_arr = [1, 2, 3, 9]
function my_set_remove(my_arr, value) {
let result = [];
for (let i = 0; i < my_arr.length; i++) {
result = my_arr[i];
if (my_arr[i] == value) {
let new_arr = my_arr.pop[i];
return new_arr;
}
}
}
console.log(my_set_remove(my_arr, 9));
When I console.log it says undefined. Thanks in advance for your help
my_arr = my_arr.filter(child => child !== valueThatDoesntWant);i < my_arr.lengthas condition, plus.pop()is a function but you have square brackets there. It also ignores any arguments because it will remove (and return) the last element.my_arr.pop[i]attempts to access the ith property of Array.prototype.pop, which doesn't exist so returns undefined.