How to Use Intl.ListFormat in JavaScript

The Intl.ListFormat object is a built-in JavaScript API that formats arrays of strings into grammatically correct, locale-aware lists. While traditional array methods like .join(', ') can join strings, they fail to handle language-specific conjunctions (like “and” or “or”), Oxford commas, or different cultural punctuation standards. This article explains how Intl.ListFormat works, its configuration options, and how to use it to join text strings accurately across different languages.

What is Intl.ListFormat?

Intl.ListFormat is a constructor provided by the ECMAScript Internationalization API (Intl). It eliminates the need for hardcoded string concatenation when rendering a series of items in a user interface. By accepting a target locale and styling options, it automatically inserts the appropriate separators and conjunctions based on standard grammatical conventions for that language.

Basic Syntax

To use Intl.ListFormat, create a new instance with the desired locale and options, then call the format() method with an array of strings:

const formatter = new Intl.ListFormat(locales, options);
const formattedString = formatter.format(iterable);

Example: Default Usage

By default, the formatter uses the 'conjunction' type and 'long' style:

const fruits = ['Apple', 'Banana', 'Orange'];

const enFormatter = new Intl.ListFormat('en');
console.log(enFormatter.format(fruits));
// Output: "Apple, Banana, and Orange"

const esFormatter = new Intl.ListFormat('es');
console.log(esFormatter.format(fruits));
// Output: "Apple, Banana y Orange"

const jaFormatter = new Intl.ListFormat('ja');
console.log(jaFormatter.format(fruits));
// Output: "Apple、Banana、Orange"

Configuration Options

The options parameter allows you to control how the list is constructed through two main properties: type and style.

1. The type Property

The type option determines the semantic relationship between the items in the list.

2. The style Property

The style option controls the length and verbosity of the formatted output.

Working with formatToParts()

If you need to render lists into structured elements—such as wrapping list items in HTML tags while keeping the separators as plain text—use the formatToParts() method instead of format().

This method returns an array of objects representing each piece of the list:

const items = ['Red', 'Green', 'Blue'];
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });

const parts = formatter.formatToParts(items);
console.log(parts);
/*
[
  { type: 'element', value: 'Red' },
  { type: 'literal', value: ', ' },
  { type: 'element', value: 'Green' },
  { type: 'literal', value: ', and ' },
  { type: 'element', value: 'Blue' }
]
*/

This makes it straightforward to map over the parts in frameworks like React or Vue to apply custom styling or components specifically to the elements without hardcoding punctuation.