Last active
February 11, 2020 14:02
-
-
Save said-and-done/b5b32102963bbbed6d50c351becc0904 to your computer and use it in GitHub Desktop.
List items with Oxford comma
This file contains hidden or 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
| let items = [ | |
| {name: 'A'}, | |
| {name: 'B'}, | |
| {name: 'C'} | |
| ]; | |
| let serial = items.map((item) => { | |
| return item.name | |
| }).reduce((prevVal, currVal, currentIndex, array) => { | |
| var delim = currentIndex === array.length-1 ? ', and ': ', ' | |
| return prevVal + delim + currVal; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment