JavaScript Último elemento da matriz
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"
var my_array = /* some array here */;
var last_element = my_array[my_array.length - 1];
// Method - 1 ([] operator)
const arr = [5, 3, 2, 7, 8];
const last = arr[arr.length - 1];
console.log(last);
/*
Output: 8
*/
// Method - 2 (Destructuring Assignment)
const arr = [5, 3, 2, 7, 8];
arr.slice(-1).pop()
Last Item In Array