Find which part of strings are different - Javascript String Operation

Javascript examples for String Operation:String Compare

Description

Find which part of strings are different

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
var String1 = "Java1String",
 String2 = "Java2String",
 String3 = "Java3Stringaa";
var String1array = String1.split('');
var String2array = String2.split('');
var j = 0;//from ww w  .j av a2  s.c  o  m
var index;
for(var i = 0; i < String1array.length; i++){
    if(String1array[i] != String2array[j])
        index = i;
    j++;
}
console.log(index);

      </script>  
   </body>
</html>

Related Tutorials