[an error occurred while processing this directive]

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.

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

Output will be displayed as:

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

Download Source Code


[an error occurred while processing this directive]