Member-only story

How to get Array Last Item in Javascript

Atiq ur rehman
Sep 15, 2023

Two methods to get last item from last index of array

Get the last item in an array
How to get Last value 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

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Atiq ur rehman
Atiq ur rehman

No responses yet

Write a response