Remove Duplicates From Array in AngularJs
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.exampleArray = ['100','98','98','88','101','102','102']; $scope.result = []; $scope.removeDuplicates = function() { $scope.result = $scope.exampleArray.filter(function(item, pos) { return $scope.exampleArray.indexOf(item) == pos; }) }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> Array With Duplicate Values = {{exampleArray}}<br> Click to Remove Duplicates Array .<br> <button ng-click='removeDuplicates()' >Remove Duplicates</button><br> Final Array = {{result}}<br> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.exampleArray = ['100','98','98','88','101','102','102']; $scope.result = []; $scope.removeDuplicates = function() { $scope.result = $scope.exampleArray.filter(function(item, pos) { return $scope.exampleArray.indexOf(item) == pos; }) }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> Array With Duplicate Values = {{exampleArray}}<br> Click to Remove Duplicates Array .<br> <button ng-click='removeDuplicates()' >Remove Duplicates</button><br> Final Array = {{result}}<br> </div> </div> </body> </html>
Copyrights@tutorialsplane.com