ES6 String对象方法localeCompare()
ES6 String对象方法localeCompare()
用本地特定的顺序来比较两个字符串。
语法
string.localeCompare(param)
参数详情
param − 要参与字符串对象比较的字符串
返回值
0−100%匹配.
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