Do something when a for loop ends
I have a for loop in JavaScript, and I wan开发者_如何转开发t some code to run when it ends. This works, but I'm wondering if there are any simpler solutions:
for (var i = 1; i <= 100; i++) {
console.log('Line ' + i);
if (i === 100) {
alert('Loop ended!');
}
}
for (var i = 1; i <= 100; i++) {
console.log('Line ' + i);
}
alert('Loop ended!');
unless I'm missing something, what's wrong with:
for (var i = 1; i <= 100; i++) {
console.log('Line ' + i);
}
alert('Loop ended!');
why dont you do like this?
Array.from(Array(100), (_, i) => console.log('Line ' + (i + 1)));
alert('Loop ended!');
Try this
for (var i = 1; i <= 100; i++) {
console.log('Line ' + i);
}
alert('');
精彩评论