有。但是该函数称为splice
。
要删除索引为n
的项目:
myArray.splice( n,1 );
,
要按索引删除,请使用Array.splice(index,remove_count)
方法。例子
var words = [‘spray’,‘limit’,‘elite’,‘exuberant’,‘destruction’,‘present’];
// We will remove the item in index 1. (limit)
words.splice(1,1);
console.log(words);
// prints [ 'spray','elite','exuberant','destruction','present' ]
要通过功能删除,请使用filter
方法:
它基于该函数创建一个新的数组。示例:
var words = [‘spray’,‘present’];
// Removes words having length less than 6
const result = words.filter(word => word.length < 6);
console.log(result); // prints [ 'spray','limit','elite' ]
本文链接:https://www.f2er.com/3169106.html