How to find array size in angularjs

how to find array size in angularjs

below is the code

<!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="namesCtrl"> <p>Looping with objects:</p> <ul> <li ng-repeat="x in names"> {{ x.name}} </li> </ul> </div> $scope.names = [ {name:'Jani'} , {name:'raaj'} ]; }); </script> </body> </html> 

here i need the size of the array of names help me in getting the size of the array using angualrjs

Please help me

+7
angularjs
source share
2 answers

Just use the length property for the Javascript array as follows:

 $scope.names.length 

Also, I don't see the start tag <script> in your code.

If you need a length inside your view, do it like this:

 {{ names.length }} 
+16
source share

You can find the number of members in a Javascript array using the length property:

 var number = $scope.names.length; 

Documents - Array.prototype.length

+2
source share

All Articles