delete element from array javascript by index code example
Example 1: remove a particular element from array
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 2: javascript remove from array by index
array.splice(index, 1);
Example 3: how to remove element from array in javascript
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 4: 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 5: 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)
Example 6: js remove if
ar = [1, 2, 3, 4];
ar = ar.filter(item => !(item > 3));
console.log(ar)