var cache = [];
cache[0] = "0";
cache[1] = "1";
cache[2] = "2";
cache[3] = "3";
cache[4] = "4";
cache["r"] = "r";
console.log(cache.length);
for(key in cache){
if(isNaN(key))continue;
else cache.splice(key,1); // cache.splice(key) is working fine, ***
}
console.log(cache);
问题:***
为什么 splice(key) 工作正常(删除所有具有数字索引的元素)和 splice(key,1) 不能正常工作(不删除具有数字索引的元素)。即使我尝试过
splice(key,1) // Not working as splice(key)
splice(key--,1) // Even not working as splice(key)
splice(key,0) // not deleting any thing
您可以在 Firebug 控制台中复制和粘贴代码进行测试。