avascript loop last index code example
Example 1: js detect end of array
var group = ["a","b","c","d"];
var groupLength = group.length;
while (groupLength--) {
var item = group[groupLength];
if(groupLength == 0){
console.log("Last iteration with item : " + item);
}
}
Example 2: javascript loop last index
for (const [i, value] of arr.entries()) {
if (i === arr.length - 1) {
// do your thing
}
}