我一直在努力編碼一段時間,功能似乎很好,但循環是痛苦的。在JS中爲for循環重新分配變量是什麼意思?
我對此非常瞭解,除了以j = i開頭的那一行,它指的是什麼?
text = "Blah blah blah blah blah blah Eric \
blah blah blah Eric blaeh blah Eric blah blah \
blah blah blah blah blah Eric";
var myName = "Eric";
var hits = [];
for(var i = 0; i < text.length; i++) {
if (text[i] === "E") {
for(var j = i; j < (myName.length + i); j++) {
hits.push(text[j]);
}
}
}
if (hits.length === 0) {
console.log("Your name wasn't found!");
} else {
console.log(hits);
}
開始內環從外部循環的當前迭代。 – Tushar
對不起,我是一個新手,並且在幾天前開始編程,請您用低技術的語言來詳細說明一下嗎? – Adam
你的內循環'j'從外循環('i')當前的任何迭代開始。所以如果'i' = 1,'j'將從1開始向上計數 – tymeJV