寻找for
和for...in
循环的最后一次迭代有多种方法。但是我如何在for...of
循环中找到最后一次迭代?我在文档中找不到相关信息。
for (item of array) {
if (detect_last_iteration_here) {
do_not_do_something
}
}
寻找for
和for...in
循环的最后一次迭代有多种方法。但是我如何在for...of
循环中找到最后一次迭代?我在文档中找不到相关信息。
for (item of array) {
if (detect_last_iteration_here) {
do_not_do_something
}
}
for...of
循环中的最后一次迭代:let iCount = 0;
for( const obj of arrObjects) {
iCount = iCount + 1;
if (iCount < arrObjects.length) {
// Some code to execute on first to (last - 1) elements
}
else {
// Some code only for the last element
}
}