Anjan Dutta

Get the last element of an array in JavaScript

Get the last element of an array in JavaScript

Published On: 02/11/2021

To access the last element of an array in javascript, we must get the array size using the .length property.

Then we can access the length - 1 th element from that array and thats it.

See the example below.

const number_list = [10, 30, 40, 80];
const len = number_list.length;
console.log(number_list[len-1]);

This way we can access the last element from an array in javascript.