Intl.PluralRules.prototype.select()

Baseline 已广泛支持

此功能已成熟,并可在多种设备和浏览器版本上使用。自 2019 年 9 月以来,它已在各种浏览器中可用。

select() 方法 Intl.PluralRules 实例返回一个字符串,该字符串指示用于本地化数字格式的复数规则。

试一试

console.log(new Intl.PluralRules("ar-EG").select(0));
// Expected output: "zero"

console.log(new Intl.PluralRules("ar-EG").select(5));
// Expected output: "few"

console.log(new Intl.PluralRules("ar-EG").select(55));
// Expected output: "many"

console.log(new Intl.PluralRules("en").select(0));
// Expected output: "other"

语法

js
select(number)

参数

数字

用于获取复数规则的数字。

返回值

表示 number 的复数化类别的字符串。它可以是 zeroonetwofewmanyother 之一。

描述

此函数根据 Intl.PluralRules 对象的语言环境和格式选项选择复数化类别。这些选项在 Intl.PluralRules() 构造函数中设置。

示例

使用 select()

首先,创建 Intl.PluralRules 对象,传入适当的 localesoptions 参数。此处我们为埃及阿拉伯语方言创建一个复数规则对象。由于未指定 type,因此规则对象将提供基数格式(默认值)。

js
const pr = new Intl.PluralRules("ar-EG");

然后,在规则对象上调用 select(),指定需要其复数形式的数字。请注意,阿拉伯语有 5 种基数形式,如下所示。

js
pr.select(0); // 'zero'
pr.select(1); // 'one'
pr.select(2); // 'two'
pr.select(6); // 'few'
pr.select(18); // 'many'

规范

规范
ECMAScript® 2026 国际化 API 规范
# sec-intl.pluralrules.prototype.select

浏览器兼容性

另见