remove value from array javascript 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: how to take an element out of an array in javascript
var data = [1, 2, 3];
data = data.splice(1, 1);
data = data.pop();
Example 3: removing first item array js
var list = ["bar", "baz", "foo", "qux"];
list.shift()
Example 4: remove item from array javascript
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 5: how to remove element from array in javascript
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 6: remove value from array javascript
let arr = [1,2,3,4,5,6];
let remove = arr.filter((id) => id !== 5)
console.log(remove)