Thursday, October 9, 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
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS