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控制台中进行测试。