javascript last element of array
snippet in javascript

javascript get last element of array

user6842

var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array

js take last item in array

user7152

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

javascript last element of array

user6978

arr.slice(-1)[0] 

javascript last element of array

user6493

let arr = [1,2,3]
arr[arr.length - 1] //returns last element in an array

javascript last element of array

user6361

var last = arr.slice(-1)[0]

javascript last element of array

user4438

let arr = ['a', 'b', 'c']
arr.slice(-1)[0] // returns last element in an array