Member-only story

Javascript Get Last Element of Array

Bipsmedium
2 min readDec 17, 2022

--

In this tutorial, I will explain javascript get last element of array. Before getting started, you must know what is an array and the length property of the array.

Also read, Generate Javascript Random Number between 1 and 10

What is an array:-

  • As we all know that an array is a variable that can hold more than one value or multiple values at a time and the index of an array starts with 0.
  • An array is declared with the keyword const.

Example of an array:- const companies = ['TCS','IBM','HCL','INFOSYS']; Length Property of the array:-

The length property counts the number of values in an array.

For eg:- If we want to find the length of the above array then it can be obtained as shown below

let company length = companies.length;

To store the length of the above array, you can declare another variable with the let keyword that holds the result which means the number of values of the above array.

In order to find javascript get last element of array, you can use the below syntax and store it in a variable as shown below

let variable name = array name[array name.length - 1];

--

--

Bipsmedium
Bipsmedium

Written by Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.

No responses yet