Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Intl.ListFormat

Joins a list into a phrase with commas and a conjunction: a, b, and c.

Available since: ES2021

Syntax

new Intl.ListFormat(locales, options)

Parameters

ParameterTypeDescription
localesstringOptional. The language.
optionsobjectOptional. type: conjunction (and), disjunction (or), unit; style: long, short, narrow.

Return value

Intl.ListFormatAn object with a format(list) method.

Examples

A list with and and with or:

const names = ['Anna', 'Oleg', 'Ivan'];
 
console.log(new Intl.ListFormat('en', { type: 'conjunction' }).format(names));
console.log(new Intl.ListFormat('en', { type: 'disjunction' }).format(names));

Output:

Anna, Oleg, and Ivan
Anna, Oleg, or Ivan

Other languages:

const names = ['Anna', 'Oleg', 'Ivan'];
 
console.log(new Intl.ListFormat('de').format(names));
console.log(new Intl.ListFormat('ru').format(names));

Output:

Anna, Oleg und Ivan
Anna, Oleg и Ivan

Notes

Unlike join(), the formatter puts a conjunction before the last item and knows the language rules — such as the comma before and in US English.

See also

In the tutorial

  • Formatting with Intl — Locale-aware formatting of numbers, money, dates and plural words in JavaScript: toLocaleString, Intl.NumberFormat, Intl.DateTimeFormat and Intl.PluralRules.

Thanks for reading!

Donate to the site — we work hard for you.