Skip to content

Instantly share code, notes, and snippets.

@icesernia
Created March 8, 2021 16:42
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 icesernia/47f1a6a88cc83f24e21b67408620dcfd to your computer and use it in GitHub Desktop.
Save icesernia/47f1a6a88cc83f24e21b67408620dcfd to your computer and use it in GitHub Desktop.
const vehicles = ['Motorcycle', 'Bus', 'Car'];
const formatter_en = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
const formatter_en_short = new Intl.ListFormat('en', { style: 'short', type: 'conjunction' });
const formatter_en_narrow = new Intl.ListFormat('en', { style: 'narrow' });
const formatter_th = new Intl.ListFormat('th', { style: 'long', type: 'disjunction' });
console.log(formatter_en.format(vehicles)); // expected output: Motorcycle, Bus, and Car
console.log(formatter_en_short.format(vehicles)); // expected output: Motorcycle, Bus, & Car
console.log(formatter_en_narrow.format(vehicles)); // expected output: Motorcycle, Bus, Car
console.log(formatter_th.format(vehicles)); // expected output: Motorcycle Bus หรือCar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment