Iterate Through an Array with a For Loop? (Sorry for no explanation.) I’ll be happy if anyone asks me to explain. I’ll love to do it.
Here is the solution:
// Setup
const myArr = [2, 3, 4, 5, 6];
for (let total = 0; total <= myArr.push(myArr.length); total += 20) {
console.log(myArr[total]);
}
console.log(myArr);
// Only change code below this line
You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.
Yes, I have a question about how this code works and solves the problem. What’s the back-end computer process?
for (let total = 0; total < myArr.push(myArr.length); total += 20)
Can you please guide me on this one so I know how it works? If I’m thinking wrong, I’m curious about how to solve this using methods like .puch() and .length().
I feel lucky to be here. And feel confident that someone is there to help me.
Right. Because the total is not the loop iteration variable. i is the loop iteration variable. You only initialize the loop iteration variable inside of the head of the loop.