Thursday, September 4, 2025
HomeLanguagesJavascriptJavaScript Array length Property

JavaScript Array length Property

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS