JavaScript count items in Array | Example code

Use Array length Property to count items in JavaScript Array. It’s return 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:

JavaScript count items in Array

Do comment if you have any doubts and suggestions on this JS Array topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.