上代码吧
delete删除
var aa = ['aa','sdf']
for (var prop in aa) {
delete aa[prop];
console.log(aa);
}
结果
[1: "sdf"]
[]
splice删除
var bb = ['aa','sdf']
for (var prop in bb) {
bb.splice(prop,1);
console.log(bb);
}
结果
["sdf"]
并没弄通原因是什么,确实有差别