一、用delete 删除数组中元素(少用)
说明:delete: 只是被删除的元素变成了 undefined ,即数组长度不变
//定义数组 var array=["aa","dd","cc","aa"]; //方法1:delete删除数组元素 delete array[1]; //输出结果 : ["aa",undefined,"cc","aa"] getArray(array);
输出结果:
aa
undefined
cc
aa
二、用splice删除数组的元素
说明:该方法会自动改变原始数组,即每用一次splice(i,1)数组长度自动减1
var array = ["aa","dd","cc","aa"]; //方法2:删除数组元素 array.splice(1,1); //输出结果:["aa","cc","aa"] getArray(array);
输出结果:
aa
cc
aa
原文地址:https://www.cnblogs.com/yanl55555/p/11997657.html
时间: 2024-10-01 03:16:54