Mega Code Archive

 
Categories / JavaScript Tutorial / String
 

Use if statement with String localeCompare

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"); }