1var colors = ["red","blue","green"];
2var green = colors[colors.length - 1];//get last item in the array
1var foods = ["kiwi","apple","banana"];
2var banana = foods[foods.length - 1]; // Getting last element
1var colors = ["red","blue","green"];
2var green = colors[colors.length - 1]; //get last item in the array
3
1let array = [1,2,3,4,5]
2
3let sliced = array.slice(-1)[0]
4
5//OR
6
7let popped = array.slice(-1).pop()
8
9//OR
10
11let lengthed = array[array.length - 1]
1let nums = [1,2,3,4,5];
2let lastOne = nums.pop();
3// -> lastOne = 5
4// -> nums = [1,2,3,4];
1if (loc_array[loc_array.length - 1] === 'index.html') {
2 // do something
3} else {
4 // something else
5}