1var my_array = /* some array here */;
2var last_element = my_array[my_array.length - 1];
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]
1let list = ["item1", "item2", "item3", "etc"];
2let last = list.reverse()[0]
3// or
4let last = list[list.length - 1]
5// or
6let last = list.slice(-1)
1if (loc_array[loc_array.length - 1] === 'index.html') {
2 // do something
3} else {
4 // something else
5}