Not sure how efficient mapping within the filter is, but: const arr = [{ id: 1 }, { id: 2 }, { id: 1 }]; const unique = arr.filter((v, i, a) => a.map(({ id }) => id).indexOf(v.id) === i); console.log(unique); That's assuming id is your primary key Answer from Deleted User on reddit.com
🌐
Medium
dpericich.medium.com › how-to-quickly-get-a-unique-array-of-objects-in-javascript-f8a80182ee27
How to Quickly Get A Unique Array of Objects in JavaScript | by Daniel Pericich | Medium
November 1, 2024 - Unlike other scripting languages, JavaScript has no unique iterative method for dealing with collections. Instead, you are forced to use one or more forEach, map, filter, or reduce methods. With a flat array of values, this task is not difficult.
🌐
Reddit
reddit.com › r/node › how to get unique set of array of objects in javascript
r/node on Reddit: how to get unique set of array of objects in javascript
June 3, 2020 -

i have an array

friendList = [ 
                {id: 1, fName: 'Sam', lName: 'Brian', profilePic: 'sam.jpg'}, 
                {id: 2, fName: 'Dam', lName: 'Nary', profilePic: 'dam.jpg'}, 
                {id: 3, fName: 'Jam', lName: 'kent', profilePic: 'jam.jpg'}, 
                {id: 1, fName: 'Sam', lName: 'Brian', profilePic: 'sam.jpg'}, 
                {id: 3, fName: 'Jam', lName: 'kent', profilePic: 'jam.jpg'}, 
             ]

how can i get a unique array of this friendList.. such that the result is :

friendList = [ 
               {id: 1, fName: 'Sam', lName: 'Brian', profilePic: 'sam.jpg'}, 
               {id: 2, fName: 'Dam', lName: 'Nary', profilePic: 'dam.jpg'}, 
               {id: 3, fName: 'Jam', lName: 'kent', profilePic: 'jam.jpg'} 
             ]

the solutions i found on the internet are like for primitive type arrays. how to do that with array of objects

Discussions

how to get unique set of array of objects in javascript
Not sure how efficient mapping within the filter is, but: const arr = [{ id: 1 }, { id: 2 }, { id: 1 }]; const unique = arr.filter((v, i, a) => a.map(({ id }) => id).indexOf(v.id) === i); console.log(unique); That's assuming id is your primary key More on reddit.com
🌐 r/node
15
2
June 3, 2020
unique key in Array of Objects?
Seems like you’re using the wrong data structure for this use case More on reddit.com
🌐 r/typescript
14
3
July 6, 2023
Creating a new array from a deeply nested array of objects of arrays, etc.?
Can you give an example of what kind of output you want for the above example? It sounds to me like you may want to flatten? Something like: response .flatMap(obj => obj.hobbies) .flatMap(hobby=> hobby.sports) .flatMap(sport => sport.stats); which should give something like: ["hello", "ending", "location", "2009", "2022", "california", "beginning", "pizza", "banana"] You may want to deduplicate with something like: const unique= Array.from(new Set(allStats)); More on reddit.com
🌐 r/Frontend
26
23
March 5, 2022
Getting a unique list of values from an array of JavaScript objects
Hmm.... I'd use reduce for that: const newEntries = Array.from( entries.reduce((acc, item) => { acc.add(item.state) return acc }, new Set()) ) newEntries.sort() // optionally sort Then again, I'd probably do it in the data layer instead of nodejs code. SELECT DISTINCT state FROM friends ORDER BY state; Boom! More on reddit.com
🌐 r/node
4
9
July 23, 2021
🌐
CoreUI
coreui.io › blog › how-to-get-unique-values-from-a-javascript-array
How to Get Unique Values from a JavaScript Array · CoreUI
July 5, 2024 - For example, to get unique objects by the age property: const array = [ { name: 'Alice', age: 25 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 30 } ] const uniqueArray = array.filter((value, index, self) => index === self.findIndex((t) => ( t.age === value.age )) ) console.log(uniqueArray) // Output: [{ name: 'Alice', age: 25 }, { name: 'Charlie', age: 30 }] This method uses findIndex to ensure only the first occurrence of each age is included.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-return-an-array-of-unique-objects-in-javascript
How to Return an Array of Unique Objects in JavaScript ? - GeeksforGeeks
July 23, 2025 - Example: The below code uses a set to return an array of unique objects. ... // input arr let arr = [ { articleId: 101, title: "Introduction to JavaScript" }, { articleId: 102, title: "Arrays in JavaScript" }, { articleId: 101, title: "Introduction to JavaScript" }, { articleId: 103, title: "Functions in JavaScript" }, ]; // Set to get unique objects let setObj = new Set(arr.map(JSON.stringify)); let output = Array.from(setObj).map(JSON.parse); // Output console.log(output);
🌐
Josh Collinsworth
joshcollinsworth.com › blog › confirm-all-ids-are-unique-in-an-array-of-javascript-objects-using-map-and-sets
How to Check Uniqueness in an Array of Objects in JavaScript - Josh Collinsworth blog
February 17, 2020 - And call it with, e.g., isEverythingUnique(items, 'id'); (which would return false in our case, because there are two objects each with id: 42). If the function returns true, then you know all the keys are unique.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-array-of-objects-into-unique-array-of-objects-in-javascript
How to Convert Array of Objects into Unique Array of Objects in JavaScript ? - GeeksforGeeks
July 23, 2025 - This approach uses the some() method to create a unique array of objects. The some() method checks if at least one element in the array passes the test implemented by the provided function.
Find elsewhere
🌐
DEV Community
dev.to › phibya › methods-to-get-unique-values-from-arrays-in-javascript-and-their-performance-1da8
Methods to get unique values from arrays in Javascript and their performance - DEV Community
February 21, 2022 - Without further intro, let's just dive into the solutions: use Array.prototype.reduce AND (Set for primitive values OR Map for objects). Here are the code: For an array of primitive values · const uniqueArray = (array) => { return Array.from( array.reduce((set, e) => set.add(e), new Set()) ) } console.log(uniqueArray([1,2,2,3,3,3])) // [1, 2, 3] //OR simply const uniqueArray = (array) => Array.from(new Set(array))
🌐
Janik von Rotz
janikvonrotz.ch › 2022 › 01 › 18 › javascript-get-array-with-unique-objects
Janik von Rotz - JavaScript: Get array with unique objects
January 18, 2022 - In JavaScript you can use Set to get an array with unique items. However, this does not work with objects. Converting the object to a string before creating the set is the solution.
🌐
Yagisanatode
yagisanatode.com › home › blog feed › get a unique list of objects in an array of object in javascript
Get a Unique List of Objects in an Array of Object in JavaScript - Yagisanatode
January 11, 2022 - By doing this Map turns into a type of Object with a key-value pair. Now keep in mind that Object keys are the highlander of data types – there can be only one. ... It means that each key must be unique.
🌐
TutorialsPoint
tutorialspoint.com › extract-unique-objects-by-attribute-from-an-array-of-objects-in-javascript
Extract unique objects by attribute from an array of objects in JavaScript
January 17, 2023 - Step 7 ? The uniqueEmployees array contains all objects with unique emp_id, and users can iterate through it to get object values. In the example below, we have implemented the algorithm to extract the unique objects by attribute using the Map and for-of loop.
🌐
Joel Olawanle
joelolawanle.com › blog › how-to-create-an-array-of-unique-values-in-javascript
How to create an array of unique values in JavaScript | Joel Olawanle
April 1, 2023 - To create an array of unique values using a Set object, we can simply pass the original array into the Set constructor and then convert the Set back into an array using the spread operator.
🌐
YouTube
youtube.com › watch
Get a Unique List of Objects in an Array of Object in JavaScript - YouTube
To the tutorial! : https://yagisanatode.com/2021/07/03/get-a-unique-list-of-objects-in-an-array-of-object-in-javascript/00:00 Intro00:38 Build the array of o...
Published   July 3, 2021
🌐
DEV Community
dev.to › nickcosmo › creating-an-array-of-unique-objects-in-javascript-2m6b
Creating an Array of Unique Objects in Javascript - DEV Community
May 9, 2024 - So, by using JSON.stringify() on the iteratees of our array we are able to create a unique string when constructing our Map keys which serves as the unique identifier for our objects.
🌐
Flavio Copes
flaviocopes.com › home › javascript › get the unique properties of objects in a javascript array
Get the unique properties of objects in a JavaScript array
September 28, 2018 - Learn how to extract the unique values of a property from an array of objects in JavaScript, combining map() with a Set and the spread operator.
🌐
Medium
xinyustudio.medium.com › javascript-get-unique-array-elements-of-objects-remove-duplicates-in-one-line-code-yes-f54867ae2dd2
JavaScript: Get unique array elements of OBJECTS, remove duplicates in ONE-LINE code, yes! | by David Kou | Medium
October 12, 2019 - The question, in short, is to get the unique element in an array of objects (not primitives like integer), in addition, the object may not be exactly the same! Note the space highlighted in below snapshot! I pondered a while and wish to come out a solution, but before that, I googled it, and found so many solutions: How to Remove Array Duplicates in ES6 — DailyJS — Medium · Remove duplicate values from JS array — Stack Overflow · JavaScript: Remove Duplicates from an Array — William Vincent
🌐
JavaScript in Plain English
javascript.plainenglish.io › the-easy-way-to-create-a-unique-array-of-json-objects-in-javascript-5634254b17aa
The easy way to create a unique array of JSON Objects in JavaScript | by Lewis Donovan | JavaScript in Plain English
September 18, 2024 - The easy way to create a unique array of JSON Objects in JavaScript No filters, no callbacks, no dependencies and no 'for' loop 🙌 🎉 Google “JS array of unique JSON Objects” and you’ll be …
🌐
ServiceNow Community
servicenow.com › community › developer-forum › how-to-find-unique-set-of-objects-in-an-array › m-p › 1559831
Solved: How to find unique set of objects in an array - ServiceNow Community
May 21, 2022 - var obj = '[ { "name": "Joe", "age": 17,flag:"true" },{ "name": "Bob", "age": 17 ,flag:"true" },{ "name": "Carl", "age": 35,flag:"false" },{ "name": "Joe", "age": 17,flag:"true" }]'; var uni = []; var parser = new JSONParser(); var parameterArr = parser.parse(obj); for (var i = 0; i < parameterArr.length; i++) { uni.push(parameterArr[i].name.replace(/\s/g, '')); } var noDuplicates = new ArrayUtil().unique(uni.toString().split(',')); gs.print(noDuplicates);
🌐
Better Programming
betterprogramming.pub › how-to-find-unique-objects-in-an-array-in-javascript-by-object-reference-or-key-value-pairs-131338898d7a
How to Find Unique Objects in an Array in JavaScript by Object Reference or Key-Value Pairs | by Dr. Derek Austin 🥳 | Better Programming
January 5, 2023 - I’ll be exploring using Set to remove any duplicate objects from the array. First, I’ll find unique objects based on the objects’ variable name (objects with the same object reference). Then, I’ll filter for objects with identical key-value pairs (that have the same content but different object references). Before I get to coding, let’s discuss the difference between object reference and object content because it illuminates how Set works in JavaScript.
🌐
LearnersBucket
learnersbucket.com › home › examples › javascript › javascript get unique items from array
Javascript get unique items from array - LearnersBucket
May 3, 2019 - We can use the spread … along with map and Set to get the unique properties from the array of objects.