var fruit = ["apple","pear","pear","pear","banana"];
如何从该阵列中删除所有“梨”水果?
我尝试了以下方法,但仍然有一个梨:
for(var f in fruit) {
if ( fruit[f] == "pear" ) {
fruit.splice(f, 1);
}
}
for(var f in fruit) {
document.write(fruit[f]+"<br>");
}
输出:
apple
pear
banana
我做错了什么?现场演示:http: //jsfiddle.net/SbxHc/