Intl.ListFormat.prototype.format
Formats a list of strings according to the locale and style options of this Intl.ListFormat object
Syntax
listFormat.format(list)Parameters
| Parameter | Type | Description |
|---|---|---|
| list | string[] | An iterable of strings to format as a list |
Return Value
A string representing the formatted list
Examples
const lf = new Intl.ListFormat('en')
console.log(lf.format(['Alice'])) // 'Alice'
console.log(lf.format(['Alice', 'Bob'])) // 'Alice and Bob'const lf = new Intl.ListFormat('fr', { type: 'conjunction' })
console.log(lf.format(['pomme', 'banane', 'cerise']))
// 'pomme, banane et cerise'function formatAuthors(authors: string[], locale = 'en') {
if (authors.length > 3) {
const shown = authors.slice(0, 2)
return new Intl.ListFormat(locale).format([...shown, `${authors.length - 2} others`])
}
return new Intl.ListFormat(locale).format(authors)
}Understanding Intl.ListFormat.prototype.format
The Intl.ListFormat.prototype.format method in JavaScript formats a list of strings according to the locale and style options of this Intl.ListFormat object. It belongs to the Intl.ListFormat object and is one of the most widely used methods for working with intl.listformat values in modern JavaScript and TypeScript applications.
The method signature is listFormat.format(list). It accepts 1 parameter: list. When called, it returns a string representing the formatted list. Understanding when and how to use format() helps you write more expressive, readable code.
Common use cases for Intl.ListFormat.prototype.format include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like intl-listformat, intl-numberformat-format, intl-pluralrules, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Intl.ListFormat.prototype.format is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Intl.ListFormatCreates an Intl.ListFormat object that enables language-sensitive list formatting
Intl.NumberFormat.prototype.formatFormats a number according to the locale and formatting options of this Intl.NumberFormat object
Intl.PluralRulesCreates an Intl.PluralRules object that enables plural-sensitive formatting and language-specific rules for plurals
Related Tools
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.