JavaScript

Intl.Collator オブジェクト


編集:2023.01.20 by T.A.

[Edge]。→

言語を考慮した文字列の比較を可能にするオブジェクト。

コンストラクター
new Intl.Collator([locales[, options]])
新しい Intl.Collator オブジェクトを生成して返します。
静的メソッド
Intl.Collator.supportedLocalesOf(locales[, options])
言語を考慮した文字列の比較で対応可能なロケールの文字列の配列で返します。
インスタンス メソッド
Intl.Collator.compare(string1, string2)
Intl.Collator により、指定の 2 つの文字列を比較した結果を数値で返します。
Intl.Collator.resolvedOptions()
Intl.Collator のオプションの計算された設定値を新しいオブジェクトで返します。
DA=new Intl.Collator('ja-JP', {numeric:true});  //数字は数値として比較。
D=DA.compare("10", "2");   //=[number]:1。「2」が先。
D=DA.compare("a10", "a2"); //=[number]:1。「a2」が先。

テスト