Member-only story
How to get Array Last Item in Javascript
Sep 15, 2023
Two methods to get last item from last index of array
First method:
we use arr.length-1 for getting array item that is in last index
var arr = [1, 2, 3, 4, 5]
console.log(arr[arr.length-1])
//5
Second method:
we use arr.at(-1) for getting array item that is in last index
var arr = [1, 2, 3, 4, 5]
console.log(arr.at(-1))
//5