Remove Duplicates value from Array using AngularJS

Remove Duplicates value from Array using AngularJS

how to prevent duplicate in array push in angularjs

First we need an al the array check which have duplicate values available or not so we will create an array other array with duplicate values and then this array process to remove all the duplicate values.Remove Duplicates value from Array using AngularJS -angularjs unique array

index.html



<title>Remove Duplicates From Array in AngularJs Example</title>
 <a href="http://angular.min.js">http://angular.min.js</a>
 
var liveApp = angular.module("liveApp", []);
 liveApp.controller("liveCtrl", function($scope) {
$scope.ageArrayval = ['25','44','98','44','50','71','50'];
$scope.dataresult = [];
 $scope.deleteDuplicate = function() {
     $scope.dataresult = $scope.ageArrayval.filter(function(item, pos) {
     return $scope.ageArrayval.indexOf(item) == pos;
     })
 };
});


  
<div>  
	<div> 
	 Array With Duplicate Values = {{ageArrayval}}
	 Click to simple Remove all the Duplicates Array .
	 <button>Remove your Duplicates Value</button><br>
	 Result : Final Array = {{dataresult}}<br>

	</div> 
</div>

<a href="https://infinityknow.com" target="_blank" title="Download,free download,steps download,download quickly,easy download,steps download,all download" class="download">Example</a>


  
 

AngularJs Remove duplicate elements in ng-repeat Example

Just simple create a filter with remove duplicate id that gets the unique values

READ :  How To Resolve jQuery is undefined error

<div></div>

app.filter('datauniq', function() {
   return function(datacol, keyname) {
      var dataout = [], 
          datakeys = [];

      angular.forEach(datacol, function(item) {
          var dk = item[keyname];
          if(datakeys.indexOf(dk) === -1) {
              datakeys.push(dk);
              dataout.push(item);
          }
      });

      return dataout;
   };
});

Example

Leave a Reply

Your email address will not be published. Required fields are marked *