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;
});
Just use the:
.toLowerCase()
method.
In your case:
if(a.product.productName.toLowerCase() < b.product.productName.toLowerCase()){
return -1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With