现在的位置: 首页 > 综合 > 正文

js remove from array

2018年05月22日 ⁄ 综合 ⁄ 共 305字 ⁄ 字号 评论关闭

First, find the index of
the element you want to remove:

var array = [2, 5, 9];
var index = array.indexOf(5);

Then remove it with splice:

if (index > -1) {
    array.splice(index, 1);
}

The second parameter of splice is
the number of elements to remove. Note, splice modifies
the array in place and returns a new array containing the elements that have been removed.

【上篇】
【下篇】

抱歉!评论已关闭.