大网数据广告活动
Web 标准与前端开发

Intl.PluralRules.prototype.select()

· 52CE 我爱测

The **`select()`** method of Intl.PluralRules instances returns a string indicating which plural rule to use for locale-aware formatting of a number.

The select() method of Intl.PluralRules instances returns a string indicating which plural rule to use for locale-aware formatting of a number.

JavaScript Demo: Intl.PluralRules.prototype.select()

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"

Syntax

select(number)

Parameters

  • number
    • : The number to get a plural rule for.

Return value

A string representing the pluralization category of the number. This can be one of zero, one, two, few, many, or other.

Description

This function selects a pluralization category according to the locale and formatting options of an Intl.PluralRules object. These options are set in the Intl.PluralRules() constructor.

Examples

Using select()

First, create an Intl.PluralRules object, passing the appropriate locales and options parameters. Here we create a plural rules object for Arabic in the Egyptian dialect. Because the type is not specified the rules object will provide formatting for cardinal numbers (the default).

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

Then call select() on the rules object, specifying the number for which the plural form is required. Note that Arabic has 6 forms for cardinal numbers, as shown.

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

Specifications

Browser compatibility

See also

  • Intl.PluralRules

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。