Movatterモバイル変換


[0]ホーム

URL:


  1. Веб-технологии для разработчиков
  2. JavaScript
  3. Справочник по JavaScript
  4. Стандартные встроенные объекты
  5. Intl
  6. Intl.ListFormat

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

Intl.ListFormat

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨апрель 2021 г.⁩.

ОбъектIntl.ListFormat представляет собой конструктор объектов, включающих языка-зависимое форматирование списков.

Интерактивный пример

const vehicles = ["Motorcycle", "Bus", "Car"];const formatter = new Intl.ListFormat("en", {  style: "long",  type: "conjunction",});console.log(formatter.format(vehicles));// Expected output: "Motorcycle, Bus, and Car"const formatter2 = new Intl.ListFormat("de", {  style: "short",  type: "disjunction",});console.log(formatter2.format(vehicles));// Expected output: "Motorcycle, Bus oder Car"const formatter3 = new Intl.ListFormat("en", { style: "narrow", type: "unit" });console.log(formatter3.format(vehicles));// Expected output: "Motorcycle Bus Car"

Синтаксис

new Intl.ListFormat([locales[, options]])

Параметры

locales

Необязательный параметр. Строка с языковой меткой BCP 47 или массив таких строк. Описание общей формы и интерпретации аргументаlocales смотрите на страницеIntl.

options

Необязательный параметр. Объект с некоторыми или всеми из следующих свойств:

  • localeMatcherИспользуемый алгоритм сопоставления локалей. Возможные значения:"lookup" и"best fit"; по умолчанию используется"best fit". Подробнее см. на страницеIntl.
  • typeФормат вывода. Возможные значения:"conjunction" для вывода значений через "и" (используется по умолчанию, прим.A, B и C) или"disjunction" для вывода значений через "или" (прим.A, B или C)."unit" для вывода значений с единицами измерений (прим.5 фунтов, 12 унций).
  • styleСтиль форматирования вывода. Возможные значения:"long" (используется по умолчанию, прим.A, B и C);"short" или"narrow" (прим.A, B, C). При использованииnarrow, параметрtype может принимать только значениеunit.

Описание

Свойства

Intl.ListFormat.prototype

Позволяет добавлять свойства ко всем объектамIntl.ListFormat

Методы

Intl.ListFormat.supportedLocalesOf()

Возвращает массив, содержащий те из переданных ему локалей, которые поддерживаются без необходимости использовать локаль по умолчанию.

Примеры

Использованиеformat

Пример ниже показывает как создать объектListFormat с поддержкой форматирования на русском языке и получить отформатированную строку с помощью методаformat.

js
const list = ["Motorcycle", "Bus", "Car"];console.log(  new Intl.ListFormat("ru-RU", { style: "long", type: "conjunction" }).format(    list,  ),);// > Motorcycle, Bus и Carconsole.log(  new Intl.ListFormat("ru-RU", { style: "short", type: "disjunction" }).format(    list,  ),);// > Motorcycle, Bus или Carconsole.log(  new Intl.ListFormat("ru-RU", { style: "narrow", type: "unit" }).format(list),);// > Motorcycle Bus Car

ИспользованиеformatToParts

Пример ниже показывает как получить отформатированные части объектаListFormat с помощью методаformatToParts.

js
const list = ["Motorcycle", "Bus", "Car"];console.log(  new Intl.ListFormat("en-GB", {    style: "long",    type: "conjunction",  }).formatToParts(list),);// > [ { "type": "element", "value": "Motorcycle" }, { "type": "literal", "value": ", " }, { "type": "element", "value": "Bus" }, { "type": "literal", "value": ", and " }, { "type": "element", "value": "Car" } ];

Спецификации

Specification
ECMAScript® 2026 Internationalization API Specification
# listformat-objects

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp