javascript for check for last element code example
Example 1: get last item in array javascript
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
Example 2: 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);
}
}