🔙 String prototype locale compare
6/11/2020
The localeCompare is a String function in JavaScript that returns an integer indicating whether the firstString comes before, after or is equivalent to the secondString.
TIL about localeCompare, used that to sort a object based on a string property. It's pretty handy and you can pass locale param and get that sorted right for that locale 😀.https://t.co/nEWVrjUa3y pic.twitter.com/YvHoYBj7Vg
— Rafael Nunes (@peaonunes) June 11, 2020
It implements the compartor logic returning a negative number when the firstString occurs before secondString, a positive number the other way around, and 0 if they are equivalent. Beyond that, it may take locales so the method is localized by default.