xxxxxxxxxx
const list = [1, 2, 3, 4, 5];
const lastElement = list[list.length - 1];
console.log(lastElement); // Output: 5
xxxxxxxxxx
var numbers = ["one", "two", "three"];
var lastnumber = numbers[numbers.length - 1];
console.log(lastnumber);
xxxxxxxxxx
let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];
xxxxxxxxxx
let list = ["item1", "item2", "item3", "etc"];
let last = list.reverse()[0]
// or
let last = list[list.length - 1]
// or
let last = list.slice(-1)
xxxxxxxxxx
const colors = ['black', 'white', 'red', 'yellow'];
const yellow = colors.at(-1);