Skip to content

Instantly share code, notes, and snippets.

@Mulperi
Last active November 19, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mulperi/8bcd92c6530c7bd07d53ed52fb612eef to your computer and use it in GitHub Desktop.
Save Mulperi/8bcd92c6530c7bd07d53ed52fb612eef to your computer and use it in GitHub Desktop.
JavaScript Array.reduce example
// Return array containing unique item names.
return items.reduce(
(filteredArray: any, currentItem: Item) => {
if (!filteredArray.includes(currentItem.name)) {
filteredArray.push(currentItem.name);
}
return filteredArray;
},
[]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment