JavaScript and JQuery Essentials Trainin... (46 Blogs) Become a Certified Professional
AWS Global Infrastructure

Front End Web Development

Topics Covered
  • AngularJS (20 Blogs)
  • jQuery UI Development (1 Blogs)
  • The Complete WebDeveloper (34 Blogs)
  • ReactJS (7 Blogs)


myMock Interview Service for Real Tech Jobs


Array Length In JavaScript: All You Need To Know About Length Property In JavaScript

Last updated on Jul 15,2019 70 Views


myMock Interview Service for Real Tech Jobs


myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

Arrays play a very important role when it comes to holding data to be programmed. Likewise JavaScript is a popular scripting language with strong market hold. This article on ‘Array Length In Java’ will help you explore ‘Length’ functions concerning arrays in JavaScript. Following are the pointers this article will touch up on,

Let us start with the first topic of discussion,

Array Length in JavaScript

So how do we calculate the length of array in JavaScript? The length of an array in JavaScript can be found methodically by using  the length property also known as JavaScript Array Length property. The length property can do multiple jobs, including returning or setting the number of elements in the array as it returns an unsigned 32 bit integer.

The value returned is an unsigned integer. The length property can be specified as:


We can refer to the program below for a better understanding, start with installation first:


<script type="text/javascript">
var music = new Array();
music[0] = "Rock";
music[1] = "Pop";
music[2] = "Jazz";
music[3] = "Blues";



Another way to use the length property is as follows:


//JavaScript to illustrate length property
function fun() {
// length property for array
// length property for string
<p style="text-align: justify;">

It should be noticed that in case of strings, the length property returns the number of characters present in the string, while in case of arrays, the number of elements present in the array is returned.




Let us now see how can we display elements using length.

Displaying the elements using length

In the following program, the last element of the array is accessed by using the following method: (music.length-1), after which the element is displayed.


<script type="text/javascript">
var music = new Array();
music[0] = "Rock";
music[1] = "Pop";
music[2] = "Jazz";
music[3] = "Blues";



Let us move to the last bit of this article and see how can we find out number of words present, with help of length.

Finding out the number of words present using length

Length can be used to find out the number of words present in a string. We also make use of the split function to create an array.

<script type="text/javascript">
//creating a string
var str="Music is a great way to relax. And rejuvenate";
//creating an array
var arr = new Array();
//using the split function
arr=str.split(" ");
document.write("Total Number Of Words: "+ arr.length);


Total Number Of Words: 9

Finding out the length of an array is not only a fundamental requirement, but also holistic approach to many problems.

With this we come to the end of this blog on ‘Array Length In JavaScript’. I hope you found this informative and helpful, stay tuned for more tutorials on similar topics.You may also checkout our training program to get in-depth knowledge on jQuery along with its various applications, you can enroll here for live online training with 24/7 support and lifetime access.

Got a question for us? Mention them in the comments section of  this blog and we will get back to you.


Browse Categories

Subscribe to our Newsletter, and get personalized recommendations.