question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use case suggestion: Get unique values from object array property

See original GitHub issue
const objects = [
 { id: 1 , category: "Cars", brand: "Subaru" },
 { id: 2 , category: "Cars", brand: "Ford" },
 { id: 3 , category: "Smatphones", brand: "Apple" },
 { id: 4 , category: "Cars", brand: "Citroen" },
];

categories = [...new Set(objects.map(object => object.category))];

console.log(categories);
//=> [ "Cars", "Smartphones" ]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jadjoubrancommented, Mar 8, 2018

🎬, more info on #97

1reaction
sabatesdurancommented, Mar 5, 2018

Now I see that could be maybe just remove duplicates in array.

const items = [ "Cars", "Cars", "Smartphone", "Cars" ];

const uniqueItems = [...new Set(items)];

console.log(uniqueItems);
//=> [ "Cars", "Smartphones" ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Create array of unique objects by property - javascript
Below is a general function to obtain a unique array of objects based on a specific property ( prop ) from an array...
Read more >
How to Find Unique Values by Property in an Array of Objects ...
Let's find the distinct values for a given property among all of the JavaScript objects in an array in this short tutorial.
Read more >
How to Get Distinct Values From an Array of Objects in ...
One way to get distinct values from an array of JavaScript objects is to use the array's map method to get an array...
Read more >
How to Find Unique Values of a Specific Key in an Array of ...
In this article we'll cover two separate algorithms to accomplish this and wrap up the guide with a recommendation for generalizing the strategy ......
Read more >
Compare two array's by object and compose unique r...
I have two arrays of objects that I'm trying to compare. I only want to keep the records that are unique and write...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found