javascript check if is last item 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: js detect end of array
var group = ["a","b","c","d"];
var groupLength = group.length;
for(var i = 0;i < groupLength;i++){
var item = group[i];
if((i + 1) == (groupLength)){
console.log("Last iteration with item : " + item);
}
}