“JavaScript удалить элемент из массива” Ответ

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

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

JavaScript удалить элемент из массива

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 удалить элемент из массива

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

JavaScript удалить элемент из массива

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 удалить элемент из массива

array.remove(number);
Frightened Fox

JavaScript удалить элемент из массива

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

Ответы похожие на “JavaScript удалить элемент из массива”

Смотреть популярные ответы по языку

Смотреть другие языки программирования