JavaScript – Length of Array
To get length of an array in JavaScript, access length property of this array.
length property returns the number of elements in this array.
The syntax to read the length property of an array arr
is
</>
Copy
arr.length
Example
In the following example, we have taken an array in arr
. We shall find the length of this array arr
using length property.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div id="output"></div>
<script>
var arr = ['apple', 'banana', 'cherry', 'mango'];
var len = arr.length;
document.getElementById('output').innerHTML = 'Array Length : ' + len;
</script>
</body>
</html>
Conclusion
In this JavaScript Tutorial, we learned how to find length of an array using length property, with examples.