JavaScript

Intl.Collator.prototype.compare() メソッド


編集:2022.12.20 by T.A.

[Edge]。→

Intl.Collator により、指定の 2 つの文字列を比較した結果を数値で返します。

Intl.Collator.compare(string1, string2)
Intl.Collator Intl.Collator オブジェクト。
string1string2 互いに比較する文字列です。
戻り値

数値。string1string2 の前に来る場合は負の数。逆なら正の数。等しいなら 0。

DA=new Intl.Collator('ja-JP', {numeric:true});  //数字を数値として比較。
D=DA.compare("10", "2");  //=[number]:1。「2」の方が先。
D=DA.compare("a10", "a2");  //=[number]:1。「a2」の方が先。

new Intl.Collator()


テスト