Home Java Javascript-array JavaScript Array Count



JavaScript Array Count
Posted on: November 11, 2008 at 12:00 AM
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. 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

Related Tags for JavaScript Array Count:
javajavascriptcarrayclasssyntaxprototypescriptiocountpropertymethodsedtypeipusingdeclarationlengthshowifforexampletoexamsheaxcanusepeinasmntcajclestaxallmehowproxaxampseeatratiohallivmplproperraygoandarcodcodertropevascrssriripthshoavatihateclpleplpropprndonlyodeononl


More Tutorials from this section

Ask Questions?    Discuss: JavaScript Array Count  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.