How to count array items in AngularJS ? Last Updated : 21 Feb, 2023 Comments Improve Suggest changes 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 count array items 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 How to Sort an Array based on User Input in AngularJS ? AngularJS is a JavaScript-based framework. It can be used by adding it to an HTML page using a <script> tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. In this article, we will see how to sort an array based o 3 min read How to use comma as list separator in AngularJS ? In this article, we will use commas as a list separator in AngularJS applications.In AngularJS, we can use a list separator by simply placing the command between the items in the list. If we have an array of items that we need to display in the application, then we can use ng-repeat to iterate throu 4 min read How to make empty an array using AngularJS ? Given an array & the task is to make empty an array or delete all the elements from the array in AngularJS. In order to do this, there are 2 ways i.e., either use the [] notation to reinitialize the array which eventually removes all the elements from the array, or set the length of the array to 2 min read How To Consuming JSON APIs in AngularJS Application? AngularJS is a powerful JavaScript framework that makes it easy to build dynamic web applications. One of the common tasks in modern web applications is consuming data from RESTful APIs, often in the form of JSON. This article will walk you through the steps to consume JSON APIs in an AngularJS appl 2 min read Like