Click here to Skip to main content
12,956,410 members (77,858 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi All,

How to compare two string i.e

str1 = 1,2,3,4,5
str2 = 2,4,5

i need result as 1,3 using javascript is possible

Thanks in Advance
Seshu
Posted 13-Jul-11 0:58am
hiseshu523
Comments
Sunasara Imdadhusen 13-Jul-11 9:24am
   
not a question!!

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

<script language="javascript">
var Array1 = new Array("a","b","c","d","e","f");
//var Array1 = str1.split(",")
var Array2 = new Array("c","e");
//var Array2 = str2.split(",")
for (var i = 0; i<Array2.length; i++) {
    var arrlen = Array1.length;
    for (var j = 0; j<arrlen; j++) {
        if (Array2[i] == Array1[j]) {
            Array1 = Array1.slice(0, j).concat(Array1.slice(j+1, arrlen));
        }//if close
    }//for close
}//for close
alert(Array1);
</script>


Note: you may remove commented code for your requirement.

Thanks,
Imdadhusen
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100