> For the complete documentation index, see [llms.txt](https://til.duyet.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.duyet.net/programming/javascript-typescript/intl.listformat.md).

# Intl.ListFormat

```javascript
const books = [
    'Harry Potter',
    'Bhagavad Gita',
    'The Alchemist',
    'Birthday Girl'
]

const listFormatter1 = new Intl.ListFormat('en', {
    style: 'long',
    type: 'conjunction'
})
console.log(listFormatter1.format(books));
// Harry Potter, Bhagavad Gita, The Alchemist, and Birthday Girl

const listFormatter2 = new Intl.ListFormat('en-GB', {
    style: 'short',
    type: 'disjunction'
})
console.log(listFormatter2.format(books));
// Harry Potter, Bhagavad Gita, The Alchemist, or Birthday Girl

```

The first part is to create the formatter using the `Intl.ListFormat` method. This method accepts two optional parameters.

* `locales` - A string with a BCP 47 language tag, or an array of such strings.
* `options` - An object with some or all of the following properties:
  * `localeMatcher` - The locale matching algorithm to use. Possible values are `lookup` and `best fit`; the default is `best fit`.
  * `type` - The format of the output message. Possible values are `conjunction` that stands for “and”-based lists (default, e.g., “A, B, and C”), or `disjunction` that stands for “or”-based lists (e.g., “A, B, or C”). `unit`stands for lists of values with units (e.g., “5 pounds, 12 ounces”).
  * `style` - The length of the formatted message. Possible values are: `long`(default, e.g., “A, B, and C”); `short` (e.g., “A, B, C”), or `narrow` (e.g., “A B C”). When style is `short` or `narrow`, `unit` is the only allowed value for the type option.

Source: <https://www.amitmerchant.com/how-to-convert-arrays-to-human-readable-lists-in-javascript/>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://til.duyet.net/programming/javascript-typescript/intl.listformat.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
