Answers for "how delete element in array javascript"

23

how to remove element from array in javascript

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 April-23-2020
1

delete element from array js

// Create a function to do it easily and how many time you want!
const deleteFromArray = (array, value) => {
  let newArray = array.filter(item => item !== value)
  return newArray;
}

var array = [1, 2, 3, 4]
const newArr = deleteFromArray(array, 2)
console.log('Changed array:', newArr);
// Changed array: [ 1, 3, 4 ]
Posted by: Guest on January-13-2022

Code answers related to "how delete element in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language