Answers for "remove item from array"

265

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
17

how to take an element out of an array in javascript

var data = [1, 2, 3];

// remove a specific value
// splice(starting index, how many values to remove);
data = data.splice(1, 1);
// data = [1, 3];

// remove last element
data = data.pop();
// data = [1, 2];
Posted by: Guest on November-11-2019
8

delete item from list javascript

const array = [1, 2, 3];
const index = array.indexOf(2);
if (index > -1) {
  array.splice(index, 1);
}
Posted by: Guest on December-10-2020
9

remove item from array

const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1);
}

// array = [2, 9]
console.log(array);
Posted by: Guest on June-15-2020
0

remove item from array

$input = array("item 2", "item 4");
$key = array_search('item 2', $input);
if($key!==false){
    unset($input[$key]);
}
var_dump($input);
Posted by: Guest on April-24-2021
0

remove item from array

const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1);
}

// array = [2, 9]
console.log(array); 
 Run code snippet
Posted by: Guest on October-16-2021

Code answers related to "remove item from array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language