我正在比较两个字符串,我想在比较之前将一个字符串小写.我怎样才能做到这一点?这是我的代码:
this.products = response.responseData.sort(function(a,b){
if(a.product.productName < b.product.productName){
return -1;
}
if(a.product.productName > b.product.productName){
return 1;
}
return 0;
});
Run Code Online (Sandbox Code Playgroud)
Sh.*_*vel 15
只需使用:
.toLowerCase()
Run Code Online (Sandbox Code Playgroud)
方法.
在你的情况下:
if(a.product.productName.toLowerCase() < b.product.productName.toLowerCase()){
return -1;
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8068 次 |
| 最近记录: |