Use Array length Property to count items in JavaScript Array. It returns the number of elements in an array.
Return the length of an array:
array.length
Set the length of an array:
array.length = number
HTML Example code:
<!DOCTYPE HTML>
<html>
<body>
<script>
var arr = [1, 2, 3, 5, 2, 8, 9, 2];
var count = arr.length;
console.log(count);
</script>
</body>
</html>
Output:
Do comment if you have any doubts and suggestions on this JS Array topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version