How to Remove Duplicate Objects from an Array in JavaScript? Last Updated : 05 Aug, 2025 Comments Improve Suggest changes Like Article Like Report In JavaScript, it's a common example that the arrays contain objects and there might be a possibility that the objects may or may not be unique. Removing these duplicate objects from the array and getting the unique ones is a common task in Web Development. These are the following approaches: Table of Content Using SetUsing filter() and indexOf() methodUsing SetWe know that the JavaScript Set stores only the unique values, so we use the set to filter out duplicate objects.To use the set, we need to convert each object to a string using JSON.stringify() method, then add them to the set.Then filter the array based on whether the set already contains the string representation or not.At the end print the unique object of the array.Example: This example shows the implementation of the above approach. JavaScript const array = [ { id: 1, name: 'Geeks' }, { id: 2, name: 'for' }, { id: 1, name: 'Geeks' } ]; const uniqueArray = Array.from(new Set(array.map(obj => JSON.stringify(obj)))) .map(str => JSON.parse(str)); console.log(uniqueArray); Output[ { id: 1, name: 'Geeks' }, { id: 2, name: 'for' } ] Using filter() and indexOf() methodWe use the filter() method to iterate over each object in the original array.For each object in the array, we use indexOf() to check if the index of the current object is equal to the index of its first occurrence. If it is, it means the object is unique and we keep it in the filtered array.The filter method constructs a new array containing only the unique objects based on the condition described above.Finally, we print the unique array, which contains only the unique objects from the original array.Example: This example shows the implementation of the above approach. JavaScript const array = [ { id: 1, name: 'geeks' }, { id: 2, name: 'for' }, { id: 1, name: 'geeks' } ]; const uniqueArray = array.filter((obj, index, self) => index === self.findIndex(o => o.id === obj.id && o.name === obj.name ) ); console.log(uniqueArray); Output[ { id: 1, name: 'geeks' }, { id: 2, name: 'for' } ] Comment S skaftafh Follow Improve S skaftafh Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Array-Questions Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like