问题:
What is the difference between using the delete
operator on the array element as opposed to using the Array.splice
method ? 在数组元素上使用delete
运算符与使用Array.splice
方法有什么Array.splice
?
For example: 例如:
myArray = ['a', 'b', 'c', 'd'];
delete myArray[1];
// or
myArray.splice (1, 1);
Why even have the splice method if I can delete array elements like I can with objects? 如果可以像删除对象一样删除数组元素,为什么还要使用splice方法?
解决方案:
参考一: https://stackoom.com/question/26EI/在JavaScript中删除数组元素-Delete与Splice参考二: https://oldbug.net/q/26EI/Deleting-array-elements-in-JavaScript-delete-vs-splice
来源:oschina
链接:https://my.oschina.net/stackoom/blog/3220840