lodash - Count duplicate and then remove them
I am trying to use lodash to first count how many duplicates are in an array of objects and the remove the duplicate (keeping the counter). The code I have so far seem to work, but I canìt figure out how to merge the two (sorry, new with lodash). Here's some code: var array = [ {id: 1, name: "test"}, {id: 2, name: "test 2"}, {id: 3, name: "test 3"}, {id: 4, name: "test 4"}, {id: 1, name: "test "}, {id: 2, name: "test 2"}, ] // This finds the duplicates and removes them result = _.uniqBy(array, 'id') // this counts how many duplicates are in the array count = _(result) .groupBy('id') .map(