To add the equivalent of the PHP strcmp() function with JavaScript, we can use the string localeCompare
method.
For instance, we write
str1.localeCompare(str2)
to compare the values of str1
and str2
by their lexical order.
It’s aware of the locale the device is using when doing the comparison.