const array = [ { id: 3, name: 'Central Microscopy', fiscalYear: 2018 }, { id: 5, name: 'Crystallography Facility', fiscalYear: 2018 }, { id: 3, name: 'Central Microscopy', fiscalYear: 2017 }, { id: 5, name: 'Crystallography Facility', fiscalYear: 2017 } ]; const result = []; const map = new Map(); for (const item of array) { if(!map.has(item.id)){ map.set(item.id, true); // set any value to Map result.push({ id: item.id, name: item.name }); } } console.log(result)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter