Odstrániť z poľa js

Príklady kódu

211
0

odstráňte konkrétny prvok z poľa

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"]
16
0

js pole odstrániť špecifický prvok

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var removed = arr.splice(2,2);
/*
removed === [3, 4]
arr === [1, 2, 5, 6, 7, 8, 9, 0]
*/
5
0

odstrániť prvok z poľa javascript

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); 
2
0

odstrániť prvok z JavaScriptu poľa

let fruit = ['apple', 'banana', 'orange', 'lettuce']; 
// ^^ An example array that needs to have one item removed

fruit.splice(3, 1); // Removes an item in the array using splice() method
// First argument is the index of removal
// Second argument is the amount of items to remove from that index and on

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................