get last array element in js code example
Example 1: js take last item in array
const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
Example 2: javascript get last element of array
var array = [1,2,3,4,5,6];
var val = array[array.length - 1]; // 6
Example 3: js array last element get
.slice(-1)[0]