Remove duplicates with filter
After duplicates are removed, each item in the array is then set up to be an empty object so future data can be added.
by Matthew Day
JavaScript
let duplicates = ['apple', 'butter', 'butter', 'cream', 'dumplings', 'dumplings', 'dumplings', 'eggs'];
let uniques = duplicates.filter((item, index, inputArray) => {
return inputArray.indexOf(item) === index;
}).map((item, index, inputArray) => {
if(inputArray.indexOf(item) === index) {
return {[item]: {}};
}
})
console.log(uniques);
// SOURCE
// https://stackoverflow.com/questions/18008025/remove-duplicate-item-from-array-javascript