How to count array items in AngularJS ? Last Updated : 21 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Syntax: array.length();Example 1: In this example, the array length is shown by the alert box. Here, we have an array containing different array elements & we need to find the total count of the elements in an array. We have created the Controller that will calculate the total length of an array element & will display the count while clicking the button. HTML <!DOCTYPE HTML> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module("app", []); myApp.controller("controller", function($scope) { $scope.arr = ['GFG', 'Geek', 'Geeks', 'GeeksforGeeks']; $scope.length = ''; $scope.getLen = function() { $scope.length = $scope.arr.length; alert("Array Length = " + $scope.length); }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <p> How to count array items in AngularJS </p> <div ng-app="app"> <div ng-controller="controller"> <p>Array = {{arr}}</p> <button ng-click="getLen()"> Click To Get Length </button> </div> </div> </body> </html> Output: Example 2: In this example, length is shown inside the <p>element. Here, we have created a controller that is responsible to render the array with the elements, along with having a button that will display the total length of an array while clicking the button. Inside the controller, we have an array & using the arr.length() method, we will count the length of an array. HTML <!DOCTYPE HTML> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"> </script> <script> var myApp = angular.module("app", []); myApp.controller("controller", function($scope) { $scope.arr = ['GFG', 'Geek', 'Geeks', 'GeeksforGeeks']; $scope.length = ''; $scope.getLen = function() { $scope.length = $scope.arr.length; }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <p> How to count array items in AngularJS </p> <div ng-app="app"> <div ng-controller="controller"> <p>Array = {{arr}}</p> <button ng-click="getLen()"> Click To Get Length </button> <p>Length is = {{length}}</p> </div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to create the dynamic forms in AngularJS ? P PranchalKatiyar Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Questions Similar Reads How to remove an item from an array in AngularJS Scope? In the AngularJS framework, we can manipulate the data that is within the scope, for example, we can perform the operations on an array by removing its elements. This helps us for better efficiency in developing the web application.We can remove the array elements in the applications like to-do list 5 min read How to update an array element in AngularJS ? Given an array with an initial array of elements & the task is to update an array element using AngularJS. To update a particular item in an array, there are 2 ways, i.e., either by its value or by its index. Here, we will use the concept of the Property accessors method that is used to access t 2 min read How to print an array in table format using angularJS? Given an array & the task is to print the given array in the tabular format using AngularJS. In JavaScript, data can be stored in the form of arrays. Each of the array items has unique indexing, starting from 0. But what if the developer wants to display all the items that are in the array, on t 4 min read How to push elements in an array using AngularJS ? Given an array and the task is to perform the push operation on the array using AngularJS. The arr.push() method is used to push one or more values into the array, & new values will add at the end of an array. This method changes the length of the array by the number of elements added to the arr 2 min read How to create the dynamic forms in AngularJS ? In AngularJS, we need to create dynamic forms to make the user interact. We can create and apply different behaviors to the forms to represent and accept the data from the user. We can create dynamic forms using ng-repeat and ng-show in AngularJS. In this article, we will see how we can create dynam 6 min read How to concat strings using AngularJS ? In this article, we will see how to concat strings in AngularJS. There are few ways to concat the strings in AngularJS. In this article, we will see 2 of them.Example 1: In the first example, we are using the '+' operator to concat the strings HTML<!DOCTYPE HTML> <html> <head> < 2 min read Like