Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lower case a string in Typescript?

Tags:

javascript

I am comparing two strings and I want to lower case a string before comparing. How can I do this? This is my code:

 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;
                 });
like image 244
sumit maske Avatar asked Nov 28 '22 16:11

sumit maske


1 Answers

Just use the:

.toLowerCase()

method.

In your case:

if(a.product.productName.toLowerCase() < b.product.productName.toLowerCase()){
                         return -1;
                     }
like image 61
Sh. Pavel Avatar answered Dec 09 '22 21:12

Sh. Pavel