JavaScript dernier élément du tableau
let arr = [1,2,3]
arr[arr.length - 1] //returns last element in an array
Elegant Elk
let arr = [1,2,3]
arr[arr.length - 1] //returns last element in an array
const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
// Find the last item in an array.
arrayName[arrayName.length - 1]
last element of array
const arr = [1,2,3,4];
const last = arr[arr.length - 1];
console.log(last); // 4
const arr = [1,2,3,4];
const last = arr.at(-1);
console.log(last); // 4
const arr = [1,2,3,4];
const last = arr.findLast(x => true);
console.log(last); // 4
let arry = [2, 4, 6, 8, 10, 12, 14, 16];
let lastElement = arry[arry.length - 1];
console.log(lastElement);
//Output: 16