Avatar ·

How to remove a specific element from an array in JavaScript?

Hi everyone! I just started learning JavaScript and encountered a problem that seems simple, but I can't find the right solution. I have an array of numbers: ```javascript let numbers = [1, 2, 3, 4, 5]; ``` I want to remove the element with the value `3` from it. I tried using `delete numbers[2]`, but after that, `undefined` remains in place of the removed element, and the array doesn't shrink. I expect to get `[1, 2, 4, 5]`. I also tried writing my own function using a loop, but the code turned out bulky and doesn't always work correctly, especially if there are duplicates in the array. For example: ```javascript function removeItem(arr, item) { for(let i = 0; i < arr.length; i++) { if(arr[i] === item) { arr.splice(i, 1); } } } ``` This option removes the