Is there a JavaScript strcmp()?

jonathan picture jonathan · Jul 24, 2009 · Viewed 118.3k times · Source

Can anyone verify this for me? JavaScript does not have a version of strcmp(), so you have to write out something like:

 ( str1 < str2 ) ? 
            -1 : 
             ( str1 > str2 ? 1 : 0 );

Answer

newacct picture newacct · Jul 24, 2009

What about

str1.localeCompare(str2)