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
1var name = ["jon","tem","kevin", "ramos"];
2var lastNameInArray = name[name.length - 1];// >> ramos
1var my_array = /* some array here */;
2var last_element = my_array[my_array.length - 1];
3
1let arry = [2, 4, 6, 8, 10, 12, 14, 16];
2let lastElement = arry[arry.length - 1];
3
4console.log(lastElement);
5
6//Output: 16
7
1if (loc_array[loc_array.length - 1] === 'index.html') {
2 // do something
3} else {
4 // something else
5}