Answers for "js remove item"

282

javascript array remove element

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"]
Posted by: Guest on July-19-2019
23

javascript remove element

//remove a dom element
var element = document.getElementById("someId");
	element.parentNode.removeChild(element);

//remove element from array
var colors=["red","green","blue","yellow"];
var blue=colors.splice(2, 1);//first arg is array index to remove
//colors is now ["red","green","yellow"]
Posted by: Guest on June-27-2019
10

remove item at index in array javascript

// remove element at certain index without changing original
let arr = [0,1,2,3,4,5]
let newArr = [...arr]
newArr.splice(1,1)//remove 1 element from index 1
console.log(arr) // [0,1,2,3,4,5]
console.log(newArr)// [0,2,3,4,5]
Posted by: Guest on March-01-2020
9

js array delete specific element

var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){
    return value > 5;
});
//filtered => [6, 7, 8, 9]
//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Posted by: Guest on September-23-2019

Code answers related to "Javascript"

Browse Popular Code Answers by Language