read last element of array javascript code example

Example 1: get last element of array javascript

var numbers = ["one", "two", "three"];
var lastnumber = numbers[numbers.length - 1];
console.log(lastnumber);

Example 2: find last element in array javascript

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

Example 3: js array last element get

.slice(-1)[0]

Example 4: get last element in array in javascript

arr.slice(-1)[0]

Example 5: get last item of array javascript

get last item of array javascript

Tags:

Java Example