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 array.
array.length
Return Value: It returns a numerical value, denoting the number of elements in the array object.
Example: This example returns the length of array.
<!DOCTYPE html> <html> <head> <title> JavaScript Array length Property </title> </head> <body> <h1>GeeksforGeeks</h1> <h2> JavaScript Array length Property </h2> <button onclick="array()"> Click Here! </button> <p id="gfg"></p> <!-- Script to return the length of array --> <script> function array() { var colors = ["green", "blue", "red", "yellow", "black", "white" ]; document.getElementById("gfg").innerHTML = colors.length; } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Supported Browsers: The browser supported by JavaScript array length property are listed below:
- Google Chrome
- Firefox
- Internet Explorer
- Opera
- Safari
Recommended Posts:
- JavaScript | length of string and array objects
- JavaScript | Array constructor Property
- Sort array of objects by string property value in JavaScript
- JavaScript | string.length
- Find the length of a JavaScript object
- JavaScript | typedArray.length() with Examples
- How to pad a string to get the determined length using JavaScript ?
- HTML | DOM length Property
- jQuery | length property
- HTMLCollection length Property
- CSS StyleDeclaration length Property
- HTML | DOM Form length Property
- HTML | DOM History length Property
- HTML | Window length Property
- HTML | DOM Select length Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



