Last active
November 19, 2018 12:21
-
-
Save Mulperi/8bcd92c6530c7bd07d53ed52fb612eef to your computer and use it in GitHub Desktop.
JavaScript Array.reduce example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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