Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 512 Bytes

format-a-list.mdx

File metadata and controls

18 lines (14 loc) · 512 Bytes
category created tags title
Tip
2021-02-27
JavaScript
Format a list

We can take the advantage of the Intl.ListFormat object to format a list for a given locale:

const people = ['Foo', 'Bar', 'Fuzz'];

new Intl.ListFormat('en', { type: 'conjunction' }).format(people);
// 'Foo, Bar, and Fuzz'

new Intl.ListFormat('en-GB', { type: 'disjunction' }).format(people);
// 'Foo, Bar, or Fuzz'