javascript get end of array code example
Example 1: js take last item in array
const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop();
Example 2: how to get the end of an array javascript
let arr = [1, 2, 3, 4, 5, 6, 7, 8];
let last = arr.pop();
console.log(last);
console.log("https://discord.gg/5yjWgMS")
Example 3: javascript take last element of array
let array = [1,2,3,4,5];
let lastElement = array.pop();
Example 4: 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 5: 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);
}
}