javascript remove element from array
snippet in javascript

javascript remove element from array

user2849

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]

remove first element from array javascript

user7582

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();

removing first item array js

user1655


var list = ["bar", "baz", "foo", "qux"];
list.shift()//["baz", "foo", "qux"]

javascript remove element from array

user9924


var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.pop();              
// Removes the last element ("Mango") from fruits 

javascript remove element from array

user6977

const cars = ['farrari', 'Ice Cream'/* It is not an car */, 'tata', 'BMW']

//to remove a specific element
cars.splice(colors.indexOf('Ice Cream'), 1);

//to remove the last element
cars.pop();

javascript remove element from array

user2043

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]