如何在Typescript中小写一个字符串?

sum*_*ske 1 javascript

我正在比较两个字符串,我想在比较之前将一个字符串小写.我怎样才能做到这一点?这是我的代码:

 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)