Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript get last object in foreach loop

arr = [1, 2, 3]; 

arr.forEach(function(i, idx, array){
   if (idx === array.length - 1){ 
       console.log("Last callback call at index " + idx + " with value " + i ); 
   }
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #object #foreach #loop
ADD COMMENT
Topic
Name
8+9 =