array delete by index javascript code example
Example 1: javascript remove from array by index
array.splice(index, 1);
Example 2: js remove from array by value
const index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
Example 3: array remove index from array
const array = [2, 5, 9];
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 4: remove item at index in array javascript
let arr = [0,1,2,3,4,5]
let newArr = [...arr]
newArr.splice(1,1)
console.log(arr)
console.log(newArr)