JavaScript Array Count

In the given JavaScript example we are going to show you, how to count the length of array.

JavaScript Array Count

In the given JavaScript example we are going to show you, how to count the length of array.

JavaScript Array Count

JavaScript Array Count

     

In the given JavaScript example we are going to show you, how to count the length of array. For that we have to use the count() method in our code and that can be used only if we are using the property 'prototype' of Array class in our example. You can see all these declaration in the given syntax..

Here is the JavaScript code for getting the length of an array.

<html>
<head>
<h2> Count() Method in Javascript</h2>
<script>
Array.prototype.count = function () {
return this.length;
}
arr = [ 2, 4, 6, 8, 10];
arr1=arr.count();
document.write("<b>The length of Array is </b>"+arr1);
</script>
</head>
<body bgcolor="lightBlue"/>
</html>

Output will be displayed as:

In the given output, 5 is the length of array.

Download Source Code