1var colors = ["red","blue","green"];
2var green = colors[colors.length - 1];//get last item in the array
1const heroes = ["Batman", "Superman", "Hulk"];
2const lastHero = heroes.pop(); // Returns last elment of the Array
3// lastHero = "Hulk"
1let nums = [1,2,3,4,5];
2let lastOne = nums.pop();
3// -> lastOne = 5
4// -> nums = [1,2,3,4];
1let array = [0, 1, 2, 3, 4, 5, 6, 7]
2console.log(array.slice(-1));
3>>>[7]
4console.log(array.slice(-2));
5>>>[6, 7]
6console.log(array.slice(-3));
7>>>[5, 6, 7]
1if (loc_array[loc_array.length - 1] === 'index.html') {
2 // do something
3} else {
4 // something else
5}