How to make empty an array using AngularJS ? Last Updated : 01 Aug, 2022 Comments Improve Suggest changes Like Article Like Report 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 0 by using length property, which also empty the array. We will explore both the approaches & understand them through the illustrations. Approach: In this case. arr =[] will create a new array & assign a reference to it to a variable, while any other reference will remain unaffected that still points to the original array. Example 1: This example illustrates empty an array using the [] notation in AngularJS. HTML <!DOCTYPE html> <html> <head> <script src= "//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 = ['Geek', 'GeeksforGeeks', 'gfg']; $scope.emptyArr = function () { $scope.arr = []; }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to empty an array in AngularJS </h3> <div ng-app="app"> <div ng-controller="controller"> Array = {{arr}}<br><br> <button ng-click='emptyArr()'> Clear Array </button> </div> </div> </body> </html> Output: Approach: In this case, arr.length = 0 manipulates the array itself, i.e., basically deleting everything from the array & while accessing the array with the help of different variables, then we will get the modified array. Example 2: This example illustrates setting the array length to 0 using length property, which specifies an empty array. HTML <!DOCTYPE html> <html> <head> <script src= "//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 = ['Geek', 'GeeksforGeeks', 'gfg']; $scope.emptyArr = function () { $scope.arr.length = 0; }; }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to empty an array in AngularJS </h3> <div ng-app="app"> <div ng-controller="controller"> Array = {{arr}}<br><br> <button ng-click='emptyArr()'> Clear Array </button> </div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to make empty an array using AngularJS ? P PranchalKatiyar Follow Improve Article Tags : Web Technologies HTML AngularJS AngularJS-Misc Similar Reads 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 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 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 empty the content of an element using AngularJS ? In this article, we will see how to remove the content of an element in HTML DOM using AngularJS. This task can be accomplished by implementing the jQuery empty() method that removes all child nodes and their content for the selected elements. Syntax: element.empty();Parameter: This method does not 2 min read How to Delete a Row from Table using AngularJS ? Given a HTML table and the task is to remove/delete the row from the table with the help of AngularJS.Approach: The approach is to delete the row from the array where it stored and served to the table data. When the user clicks on the button near to the table row, it passes the index of that table a 2 min read Remove duplicate elements from an array using AngularJS We have given an array and the task is to remove/delete the duplicates from the array using AngularJS.Approach: The approach is to use the filter() method and inside the method, the elements that don't repeat themselves will be returned and the duplicates will be returned only once.Hence, a unique a 2 min read How to count array items 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. Syntax: array.length();Example 1: In this example, the array length is shown by the alert box. Here, we have an array containing 2 min read How to Filter 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. Angular filters can be added in AngularJS to format data. 3 min read How to get form input value using AngularJS ? Given a form element and the task is to get the form values input by the user with the help of AngularJS.Approach: We are storing the data in the JSON object after the user enters it in the input element with the help of the Angular.copy(object) method. After that, data from the JSON object can be a 2 min read How to Remove HTML element from DOM using AngularJS ? In this article, we will see how to remove particular HTML elements from the DOM with the help of AngularJS, along with understanding its implementation through the examples. For this, we can use the remove() method that helps to remove all the selected elements including all the text. Syntax: selec 2 min read Like