Sometimes you want to de-dupe an array of objects in JavaScript based on a property of the object. With ES6 it’s a bit easier to with a one line function:

const uniqify = (array, key) => array.reduce((prev, curr) => prev.find(a => a[key] === curr[key]) ? prev : prev.push(curr) && prev, []);

Pass an array and the name of the key as a string you wish to de-deplicate on and you’ll get back an array with unique values. Use it like this:

const result = uniqify(myArrayOfObjects, 'guid')

Original Eye

IT Consultancy and Software Development. Available for Freelance and Consulting work. Get in Touch!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store