last element in list js code example
Example 1: javascript last element of an array
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];
Example 2: find last element in array javascript
var heroes = ["Batman", "Superman", "Hulk"];
var lastHero = heroes.pop();
Example 3: find last element in array javascript
const numArray = [1,2,3,4,5];
const lastNumber = numArray.reverse()[0];
Example 4: javascript array last element
var lastEle = arr.slice(-1)[0];
var lastEle = arr.slice(-1).pop();