ES6 - localeCompare()



此方法返回一個數字,指示引用字串在排序順序中是在給定字串之前、之後還是與之相同。

語法

string.localeCompare( param )

引數詳情

  • 引數 − 要與字串物件進行比較的字串。

返回值

  • 0 − 如果字串完全匹配。
  • 1 − 不匹配,並且引數值在本地排序順序中位於字串物件的值之前
  • 負值 − 不匹配,並且引數值在本地排序順序中位於字串物件的值之後

示例

var str1 = new String( "This is beautiful string" );
var index = str1.localeCompare( "This is beautiful string");
console.log("localeCompare first :" + index );

輸出

localeCompare first :0
廣告
© . All rights reserved.