Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
    }
}
Comment

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];

    // Do something if is the last iteration of the array
    if((i + 1) == (groupLength)){
        console.log("Last iteration with item : " + item);
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Updating a nested object in a document using mongoose 
Javascript :: Destructuring of array in ES6 
Javascript :: For-each over an array in JavaScript 
Javascript :: break out of map javascript 
Javascript :: / w/g in javascript 
Javascript :: concatenate arrays javascript 
Javascript :: Use the parseInt Function with a Radix Javascript 
Javascript :: javascript greater than or equal to 
Javascript :: keyframe options 
Javascript :: ?. js 
Javascript :: launch json file for rust 
Javascript :: javascript date objects 
Javascript :: javascript date range 
Javascript :: js opposite of includes 
Javascript :: fetch in vue 3 
Javascript :: example custom theme material ui 
Javascript :: sort array 
Javascript :: javascript break out of map 
Javascript :: js object delete value by key 
Javascript :: JavaScript for...of loop 
Javascript :: es6 class example 
Javascript :: base64 from file 
Javascript :: remove second last element from array javascript 
Javascript :: react-native-image-viewing 
Javascript :: resize js 
Javascript :: javascript pipe async functions 
Javascript :: sails js 
Javascript :: .has js 
Javascript :: random string javascript 
Javascript :: edit message sent by discord.js 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =