Open In App
Related Articles

JavaScript Array length Property

Improve Article
Improve
Save Article
Save
Like Article
Like

The array length property in JavaScript is used to set or return the number of elements in an array. 

Syntax: It is used to set the array length.

array.length = number

It returns the length of the array.

array.length

Return Value: It returns a numerical value, denoting the number of elements in the array object

Below is an example of the Array length property.

Example: This example returns the length of the array. 

Javascript




function array() {
    let colors = ["green", "blue", "red",
        "yellow", "black", "white"];
 
    console.log(colors.length);
}
array();


Output

6

More example codes for the above property are as follows: 

Example 1: 

Javascript




let arr = new Array("Geeks", "for", "Geeks");
console.log("arr.length:" + arr.length);


Output:

arr.length:3

Example 2: 

Javascript




let arr = new Array(5, 10, 15);
console.log("arr.length:" + arr.length);


Output:

arr.length:3

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers: The browser supported by JavaScript array length property are listed below:

  • Google Chrome 1 above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 4 and above
  • Safari 1 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 26 May, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials