Angularjs remove duplicates object from objects array

By Hardik Savani | January 16, 2019 | Category : Javascript Angular

Today, i will give you example of how to remove duplicate array or object from array using js forEach. we can simply filter remove duplicates from array in angular js. you use this code for removing same entries array in json object in angular 2, angular 4, angular 6, angular 7.

in this example, we will create simple angular js json array with some duplicate array. then we will create javascript function that will remove duplicate array from our json object array. so just use bellow example and do it.


<!doctype html>



<title>Angularjs remove duplicates object from objects array -</title>

<script src=""></script>


<body ng-app='myapp'>

<h1>Angularjs remove duplicates object from objects array -</h1>

<div ng-controller="myCtrl">



<script type="text/javascript">

var app = angular.module('myapp', []);

app.controller('myCtrl', function ($scope, $location) {

var myArray = [

{ "id" : "1", "firstName" : "Hardik", "lastName" : "Savani" },

{ "id" : "2", "firstName" : "Vimal", "lastName" : "Kashiyani" },

{ "id" : "3", "firstName" : "Harshad", "lastName" : "Pathak" },

{ "id" : "1", "firstName" : "Hardik", "lastName" : "Savani" },

{ "id" : "5", "firstName" : "Harsukh", "lastName" : "Makawana" }




function removeDumplicateValue(myArray){

var newArray = [];

angular.forEach(myArray, function(value, key) {

var exists = false;

angular.forEach(newArray, function(val2, key) {

if(angular.equals(,{ exists = true };


if(exists == false && != "") { newArray.push(value); }


return newArray;




I hope it can help you...

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: