select last array element javascript code example

Example 1: last element of array javascript

var my_array = /* some array here */;
var last_element = my_array[my_array.length - 1];

Example 2: js take last item in array

const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"

Example 3: javascipt get last element of array

const arr = [1,2,3] ;
console.log(arr[arr.length - 1]);

Example 4: js array last element get

.slice(-1)[0]

Example 5: last element of array javascript

last element of array