isRepeat() function isRepeat() { var $array = [0, 0, 0, 0, 0, 0, 0, 1] console.log($array.length) for (i = 0; i < $array.length; i++) { if ($array[i] > 0) { console.log($array) } else { $array.splice(0, 1) console.log($array) console.log($array.length) } } }
为什么数组length变4后就不动了啊?我想去下前面没用的0比如0000000001,000000002,最后只剩下有效数字!
因为你的$array.length一直在变啊