Use if statement with String.localeCompare : String comparisons « String « JavaScript Tutorial






var oStringObject1 = new String("yellow");
var oStringObject2 = new String("brick");
var iResult = sTestString.localeCompare("brick");

if(iResult < 0) {
    alert(oStringObject1 + "comes before "+ oStringObject2);
} else if (iResult > 0) {
    alert(oStringObject1 + "comes after "+ oStringObject2);
} else {
    alert("The two strings are equal");
}








6.2.String comparisons
6.2.1.Compare two strings
6.2.2.String comparisons
6.2.3.String comparisons by converting strings to its uppercase form
6.2.4.localeCompare
6.2.5.Use if statement with String.localeCompare