JavaScript Array length property : The length property is used to return the total length of the array. It return the number of elements in array.
Syntax of the array length property : to get the array length use following syntax
array.length
To set the array length use follwoing syntax :
array.length = number
Example of the array length property : Here in the following example you will learn that how to get the length of the array.
Sample.html
<!DOCTYPE html>
<html>
<body>
<p>To create an array and display it's length, Click the button.</p>
<button onclick="createArray()">Create Array</button>
<p id="container"></p>
<script>
function createArray() {
var students = ["Ashok", "Nitin Kumar", "Rajesh", "Pankaj", "Sumit"];
document.getElementById("container").innerHTML = students.length;
}
</script>
</body>
</html>
Output :
5
0 Comment(s)