是這樣的,請(qǐng)看如下代碼片段:var local = [{
src: '1.jpeg'
}, {
src: '2.jpeg'
}, {
src: '3.jpeg'
}, {
src: '4.jpeg'
}, {
src: '5.jpeg'
}, {
src: '6.jpeg'
}];
var counter = 0;
btn.onclick = function () {
if (counter < local.length - 1) {
console.log(local[counter].src);
counter ++;
}
}counter到第5個(gè)的時(shí)候就過(guò)不去了,是不是條件要這樣寫counter <= local.length - 1?是這樣嗎?
簡(jiǎn)單的javascript length-1的問(wèn)題,鉆胡同里了,出不來(lái),求指教~
叮當(dāng)貓咪
2018-08-06 13:10:52