Intl.ListFormat()
constructor creates objects that enable language-sensitive list formatting.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
new Intl.ListFormat([locales[, options]])
locales
Optional. A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the
locales
argument, see the
Intl page
.
options
localeMatcher
"lookup"
and
"best fit"
; the default is
"best fit"
. For information about this option, see the
Intl
page
.
type
"conjunction"
that stands for "and"-based lists (default, e.g.,
A, B, and C
),或
"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
"long"
(default, e.g.,
A, B, and C
);
"short"
(e.g.,
A, B, C
),或
"narrow"
(e.g.,
A B C
). When
style
is
short
or
narrow
,
unit
is the only allowed value for the type option.
format
The following example shows how to create a List formatter using the English language.
const list = ['Motorcycle', 'Bus', 'Car'];
console.log(new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' }).format(list));
// > Motorcycle, Bus and Car
console.log(new Intl.ListFormat('en-GB', { style: 'short', type: 'disjunction' }).format(list));
// > Motorcycle, Bus or Car
console.log(new Intl.ListFormat('en-GB', { style: 'narrow', type: 'unit' }).format(list));
// > Motorcycle Bus Car
| 规范 |
|---|
|
Intl.ListFormat
The definition of 'ListFormat()' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ListFormat()
构造函数
|
Chrome 72 | Edge No | Firefox 78 | IE No | Opera 60 | Safari No | WebView Android 72 | Chrome Android 72 | Firefox Android No | Opera Android 51 | Safari iOS No | Samsung Internet Android No |
nodejs
13.0.0
|
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
Intl
Collator
DateTimeFormat
ListFormat
NumberFormat
PluralRules
RelativeTimeFormat
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()