目录

localeCompare()

此方法返回一个数字,指示引用字符串是在排序顺序之前还是之后或与给定字符串相同。

语法 (Syntax)

string.localeCompare( param )

参数细节 (Argument Details)

  • param - 要与字符串对象进行比较的字符串。

返回值 (Return Value)

  • 0 - 如果字符串匹配100%。

  • 1 - 不匹配,参数值位于区域设置排序顺序中字符串对象的值之前。

  • 负值 - 不匹配,参数值位于本地排序顺序中字符串对象的值之后。

例子 (Example)

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

输出 (Output)

localeCompare first :0   
↑回到顶部↑
WIKI教程 @2018