Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check last index of array in foreach typescript

// Check if, last index of array in foreach Loop.
arr = [1, 2, 3]; 

arr.forEach(function(val, index, array){
   if (index === array.length - 1){ 
       console.log("Last callback call at index " + index + " with value " + val ); 
   }
});
 
PREVIOUS NEXT
Tagged: #check #index #array #foreach #typescript
ADD COMMENT
Topic
Name
2+8 =