為什么現(xiàn)在120000這項沒刪掉
解決方案如下:
<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>
因為刪除后,原數(shù)組長度發(fā)生變化,需要校正當(dāng)前循環(huán)的位置