Open In App

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. 




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: 




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

Output:

arr.length:3

Example 2: 




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:

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


Article Tags :