JavaScript

Intl.ListFormat.prototype.formatToParts() メソッド


編集:2023.01.10 by T.A.

[Edge]。→

Intl.ListFormat で指定リストを書式化した各部分のオブジェクトの配列で返します。

構文
Intl.ListFormat.formatToParts(list)
Intl.ListFormat Intl.ListFormat
list 書式化する反復可能オブジェクト(配列 Array など)。
戻り値

以下のプロパティと値を持つオブジェクトの配列。

type
以下の値を持ちます。
element 値の要素を表す。
literal 値の要素をつなぐ物。
value
type により、以下の値を持ちます。
type が element の時 値の要素の文字列。
type が literal の時 値の要素をつなぐ文字列。 表示例: 「, 」「、」「、または」
Lst=["Cat", "Dog", "Panda"];
DA=new Intl.ListFormat('ja', {type:'disjunction'});  //日本語、グループ化の種類。
D=DA.formatToParts(Lst);  //=[object]:[object Object],[object Object],[object Object],[object Object],[object Object]
	//0=[object]:[object Object]
	//1=[object]:[object Object]
	//2=[object]:[object Object]
	//3=[object]:[object Object]
	//4=[object]:[object Object]
D[0]=[object]:[object Object]
	//type=[string]:element
	//value=[string]:Cat
D[1]=[object]:[object Object]
	//type=[string]:literal
	//value=[string]:、
D[2]=[object]:[object Object]
	//type=[string]:element
	//value=[string]:Dog
D[3]=[object]:[object Object]
	//type=[string]:literal
	//value=[string]:、または
D[4]=[object]:[object Object]
	//type=[string]:element
	//value=[string]:Panda

Intl.ListFormat()Intl.ListFormat.format()


テスト