Skip to content

Instantly share code, notes, and snippets.

@icesernia
Created Mar 8, 2021
Embed
What would you like to do?
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