Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find array size in angularjs

Tags:

angularjs

How to find array size in AngularJS

<!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 size of names array

like image 329
divya Avatar asked Mar 07 '16 17:03

divya


People also ask

How to find array length in AngularJS?

Given an array and the task is to get the length of an array variable in AngularJS. For this, we will be using the . length() method to get the length of an array variable.

How do I determine the size of an array?

We can find the size of an array using the sizeof() operator as shown: // Finds size of arr[] and stores in 'size' int size = sizeof(arr)/sizeof(arr[0]);

How to know the length of array angular?

“angular set length of array” Code Answervar len= arr. length; //Now arr. length returns 5.

How do you show the size of an array in HTML?

To find the length of an array, reference the object array_name. length. The length property returns an integer.


2 Answers

Just use the length property of a JavaScript array like so:

$scope.names.length 

Also, I don't see a starting <script> tag in your code.

If you want the length inside your view, do it like so:

{{ names.length }} 
like image 78
Saket Mehta Avatar answered Oct 06 '22 01:10

Saket Mehta


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

var number = $scope.names.length;

Docs - Array.prototype.length

like image 41
esqew Avatar answered Oct 06 '22 00:10

esqew