我想删除一个带有函数多次出现的数组中的元素.
var array=["hello","hello","world",1,"world"];
function removeItem(item){
for(i in array){
if(array[i]==item) array.splice(i,1);
}
}
Run Code Online (Sandbox Code Playgroud)
removeItem("world");
//Return hello,hello,1
Run Code Online (Sandbox Code Playgroud)
removeItem("hello");
//Return hello,world,1,world
Run Code Online (Sandbox Code Playgroud)
当循环重复两次时,此循环不会删除该元素,只删除其中一个元素.
为什么?