Skip to content

JavaScript count items in Array | Example code

  • by

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:

JavaScript count items in Array

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading