在JavaScript中删除数组元素-Delete与Splice

风格不统一 提交于 2020-04-06 17:28:40

问题:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!