Quantcast
Channel: Get list of duplicate objects in an array of objects - Stack Overflow
Browsing latest articles
Browse All 9 View Live

Answer by Cássio Lacerda for Get list of duplicate objects in an array of...

An alternative based in @ggorlen solution with new Map() as accumulator (for better performance) and without unary operator ++ (not advised by default in projects with ESLint).const values = [{ id: 10,...

View Article



Answer by HMagdy for Get list of duplicate objects in an array of objects

Let's say you have:arr = [ { id:10, name: 'someName1' }, { id:10, name: 'someName2' }, { id:11, name: 'someName3' }, { id:12, name: 'someName4' }]So, to get unique items:unique = arr .map(e =>...

View Article

Answer by Akrion for Get list of duplicate objects in an array of objects

With lodash you can solve this with filter and countBy for complexity of O(n):const data = [{ id: 10,name: 'someName1' }, { id: 10,name: 'someName2' }, { id: 11,name: 'someName3' }, { id: 12,name:...

View Article

Answer by Ori Drori for Get list of duplicate objects in an array of objects

With lodash you can use _.groupBy() to group elements by their id. Than _.filter() out groups that have less than two members, and _.flatten() the results:const values = [{id: 10, name: 'someName1'},...

View Article

Answer by Aljosha Novakovic for Get list of duplicate objects in an array of...

You haven't clarified whether two objects with different ids, but the same "name" count as a duplicate. I will assume those do not count as a duplicate; in other words, only objects with the same id...

View Article


Answer by Niall for Get list of duplicate objects in an array of objects

You can use an array to store unique elements and use filter on values to only return duplicates.const unique = []const duplicates = values.filter(o => { if(unique.find(i => i.id === o.id...

View Article

Answer by ggorlen for Get list of duplicate objects in an array of objects

You can use Array#reduce to make a counter lookup table based on the id key, then use Array#filter to remove any items that appeared only once in the lookup table. Time complexity is O(n).const values...

View Article

Answer by Saurabh for Get list of duplicate objects in an array of objects

Try thisfunction checkDuplicateInObject(propertyName, inputArray) { var seenDuplicate = false, testObject = {}; inputArray.map(function(item) { var itemPropertyName = item[propertyName]; if...

View Article


Get list of duplicate objects in an array of objects

I am trying to get duplicate objects within an array of objects. Let's say the object is like below.values = [ { id: 10, name: 'someName1' }, { id: 10, name: 'someName2' }, { id: 11, name: 'someName3'...

View Article

Browsing latest articles
Browse All 9 View Live


Latest Images