Array length Property - Javascript Array

Javascript examples for Array:length Property

Description

The length property sets or returns the number of elements in an array.

Syntax

array.length

Return Value:

A Number, representing the number of elements in the array object

The following code shows how to return the length of an array:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w  w w  .j av  a2 s.com
    var fruits = ["a","b","c","d","e"];
    document.getElementById("demo").innerHTML = fruits.length;
}
</script>

</body>
</html>

Related Tutorials