為什么現(xiàn)在120000這項(xiàng)沒刪掉
解決方案如下:
<script>
var arr=['g1','g12','g1200','g1200c','g120000','g120000c','g120001','g120001c','g1201'];
for(var i = 0; i < arr.length; i++){
if(arr[i].indexOf('c')>-1){arr.splice(i-1,2); i = i - 1;}
}
alert(arr);
</script>
因?yàn)閯h除后,原數(shù)組長(zhǎng)度發(fā)生變化,需要校正當(dāng)前循環(huán)的位置