Would it be this instead?
for (let i = 0; i < coverOpts.length; i++)
Would it be this instead?
for (let i = 0; i < coverOpts.length; i++)
That makes more sense to me.
This forEach loops over the element in an array, so it makes sense to use the length of this array in your for loop version.
Looking at how my previous codes are written.
From this:
function initCovers(coverOpts) {
coverOpts.forEach(function (opts) {
init(opts);
});
}
To this?
https://jsfiddle.net/gyn7x1mp/
function initCovers(coverOpts) {
for(let i = 0; i < coverOpts.length; i++) {
init(coverOpts[i]);
}
}
You tell us
Does the for loop work the same as the forEach loop? This should be pretty easy to test by running the code.
Everything works the same as it should.
It sounds like you could do with some refreshing your knowledge of how for loops work. I would recomend looking for a basic JS course. FCC of course offers one.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.