Categories
JavaScript Answers

How to add the equivalent of the PHP strcmp() function with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.