“JavaScript Hapus elemen dari array” Kode Jawaban

JavaScript Hapus elemen dari array

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"]
Grepper

JavaScript Hapus elemen dari array

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"]
Anxious Anaconda

JavaScript Hapus elemen dari array

const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1); // 2nd parameter means remove one item only
}

// array = [2, 9]
console.log(array); 
 Run code snippet
Splendid Skylark

JavaScript Hapus elemen dari array

> let array = ["a", "b", "c"];
> let index = 1;
> array.splice(index, 1);
[ 'b' ]
> array;
[ 'a', 'c' ]
Jolly Jackal

JavaScript Hapus elemen dari array

const array = [2, 5, 10];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1); // 2nd parameter means remove one item only
}

// array = [2, 9]
console.log(array); 
 Run code snippetHide results
Manjay Poddar

JavaScript Hapus elemen dari array

array.remove(number);
Frightened Fox

JavaScript Hapus elemen dari array

var ar = [1, 2, 3, 4, 5, 6];
    
    ar.length = 4; // set length to remove elements
    console.log( ar ); // [1, 2, 3, 4]
Handsome Hippopotamus

Jawaban yang mirip dengan “JavaScript Hapus elemen dari array”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya