Intl.ListFormat 可自动按语言规则连接列表项,如中文用顿号加“和”、英文用逗号加“and”、日文用「・」;支持 type(conjunction/disjunction)和 style(long/short/narrow)配置,现代环境可用,旧版需检测降级。

Intl.ListFormat 可以自动按目标语言的语法规则连接多个项目,比如中文用顿号、英文用逗号加 and、日文用「・」等,无需手动拼接或硬编码分隔符。
支持多语言的自然连接方式
不同语言对列表的连接词和标点习惯差异很大。例如:
- 中文:「苹果、香蕉和橙子」——顿号分隔,最后用「和」
- 英语(美国):「apple, banana, and orange」——逗号+and
- 日语:「りんご・ばなな・みかん」——中黑点连接,无连词
- 法语:「pomme, banane et orange」——逗号+et(无牛津逗号)
Intl.ListFormat 根据 locale 和 type(如 conjunction 或 disjunction)自动选择对应规则,避免出错。
基础用法:创建并格式化列表
只需传入语言标签和选项,调用 format() 即可:
const list = ['苹果', '香蕉', '橙子'];
const formatter = new Intl.ListFormat('zh-CN', { type: 'conjunction' });
console.log(formatter.format(list)); // → "苹果、香蕉和橙子"
const enFormatter = new Intl.ListFormat('en-US', { type: 'conjunction' });
console.log(enFormatter.format(['apple', 'banana', 'orange'])); // → "apple, banana, and orange"
适配不同场景的 type 和 style
type 控制逻辑关系,style 影响简洁度:
- type: 'conjunction'(默认)表示“并且”,如「A 和 B」
- type: 'disjunction' 表示“或者”,如「A 或 B」
- style: 'long'(默认):完整表达,如「A、B 和 C」
- style: 'short':更紧凑,如「A、B 或 C」→ 「A、B或C」(部分 locale 下省略空格)
- style: 'narrow':最简形式,常用于空间受限场景(如按钮、标签)
注意兼容性与降级处理
Intl.ListFormat 在现代浏览器和 Node.js 12+ 中可用,但 IE 完全不支持。若需兼容旧环境,建议:
- 用 typeof Intl.ListFormat === 'function' 检测支持性
- 不支持时回退到简单 join(如 arr.join('、')),或引入 polyfill(如 @formatjs/intl-listformat)
- 避免在服务端渲染(SSR)中假设全局 Intl 存在,应显式判断










