xxxxxxxxxx
const numArray = [1,2,3,4,5];
const lastNumber = numArray.reverse()[0];
xxxxxxxxxx
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
xxxxxxxxxx
var heroes = ["Batman", "Superman", "Hulk"];
var lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
xxxxxxxxxx
var numbers = ["one", "two", "three"];
var lastnumber = numbers[numbers.length - 1];
console.log(lastnumber);
xxxxxxxxxx
const colors = ['black', 'white', 'red', 'yellow'];
const yellow = colors.at(-1);
xxxxxxxxxx
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
const array = ["foo", "bar", "fizz", "buzz"];
const lastElem = array.at(-1); // returns "buzz"
arr.slice(-1)[0]