[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat [Back]  [Original]

Intl.ListFormat - JavaScript | MDN

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

View in English Always switch to English

Intl.ListFormat

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2021 ..

Intl.ListFormat , - .

In this article

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  Car

console.log(
  new Intl.ListFormat("ru-RU", { style: "short", type: "disjunction" }).format(
    list,
  ),
);
// > Motorcycle, Bus  Car

console.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 2027 Internationalization API Specification
# listformat-objects

Web Proxy Viewer  |  New URL  |  Original Page