Tutorialsplane

AngularJs count array items


AngularJs count array items – You can get the array length using the length method. Here in this tutorial we are going to explain how you can get the length of array variable in angularjs. You can also use our online editor to edit and run the code online.


AngularJs count array items | Example

Let us go step by step to create the array length example –

JavaScript Part

JavaScript Part Contains the following part as below –

AngularJs count array items:

 

Html Part

Html Part contains the following html as below –

AngularJs count array items in View:

<div ng-app="myApp">  
<div ng-controller="myController">  

        <button ng-click="getLength()">Click To Get Length</button>
 
 <p>Array = {{myArray}}</p>
 <p>Length = {{length}}</p>
</div> 
</div>

Complete Part

Now let us combine both html and JavaScript parts –

AngularJs count array items Example:




 
 

  
<div ng-app="myApp">  
<div ng-controller="myController">  

        <button ng-click="getLength()">Click To Get Length</button>
 
 <p>Array = {{myArray}}</p>
 <p>Length = {{length}}</p>
</div> 
</div>
  
      
                                

Try it »

If you run the above example it will produce output something like this –