Skip to content

Instantly share code, notes, and snippets.

@said-and-done
Last active February 11, 2020 14:02
Show Gist options
  • Save said-and-done/b5b32102963bbbed6d50c351becc0904 to your computer and use it in GitHub Desktop.
Save said-and-done/b5b32102963bbbed6d50c351becc0904 to your computer and use it in GitHub Desktop.
List items with Oxford comma
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