Course contentsShow
← Web Development
Lesson 2775 of 2,98249. Dates, Times, and Numbers on the WebFree lesson

Intl.ListFormat

Formatting lists of items with locale-specific conjunctions and separators.

Intl.ListFormat

You'll learn how to format arrays of items with language-appropriate conjunctions and separators using JavaScript's built-in internationalization API.

What's the Problem?

When displaying lists of items—like "apples, oranges, and bananas" or "Alice, Bob, or Carol"—different languages use different punctuation, conjunctions, and formatting rules. English uses commas and "and," but Spanish uses "y," German uses "und," and some languages don't use the Oxford comma. Manually handling these variations is error-prone and difficult to maintain.

The Solution: Intl.ListFormat

Intl.ListFormat provides locale-aware list formatting that automatically handles conjunctions, separators, and grammatical rules for you.

Basic Usage

const list = ['apples', 'oranges', 'bananas'];

const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
console.log(formatter.format(list));
// "apples, oranges, and bananas"

List Types

The type option controls the connecting word:

  • 'conjunction': "and" (apples, oranges, and bananas)
  • 'disjunction': "or" (apples, oranges, or bananas)
  • 'unit': no conjunction, for measurements (5 lb, 3 oz)

Style Options

The style option controls formatting verbosity:

  • 'long': Full words ("apples, oranges, and bananas")
  • 'short': Abbreviated ("apples, oranges, & bananas")
  • 'narrow': Minimal separators ("apples, oranges, bananas")

Locale Differences

const items = ['pommes', 'oranges', 'bananes'];

new Intl.ListFormat('fr').format(items);
// "pommes, oranges et bananes" (French uses "et")

new Intl.ListFormat('de').format(items);
// "pommes, oranges und bananes" (German uses "und")

Key Takeaway: Use Intl.ListFormat to format arrays into human-readable lists that respect locale-specific grammar, conjunctions, and punctuation rules—no manual string building required.