This content has been marked as final.
Show 5 replies
-
1. Re: Compare two array value
Chinnadk Nov 22, 2014 2:37 AM (in response to creativejoan0425)replace == with !=
-
2. Re: Compare two array value
creativejoan0425 Nov 22, 2014 3:07 AM (in response to Chinnadk)It will alert 1,3,5,6, I want the result is 1,5,6
becoz myText1 have 3 is same as myText2's 3
-
3. Re: Compare two array value
Jump_Over Nov 22, 2014 6:02 AM (in response to creativejoan0425)Hi,
Compare elements and splice input array if element found ==> so only unique elements stay.
Like this:
var text1 = "1,3,5,6", text2 = "+1,+2,3,+4,+5", toCompArr = text1.split(","), len = toCompArr.length; while (len-->0) if (mCompare (toCompArr[len], text2.split(",") ) ) toCompArr.splice(len, 1); alert ("Unique elements: " + toCompArr); function mCompare (el, array) { while (var curEl = array.pop() ) if ( curEl == el) return true; return false; }Jarek
-
4. Re: Compare two array value
creativejoan0425 Nov 23, 2014 10:08 PM (in response to Jump_Over)The result also 1,3,5,6, not 1,5,6
-
5. Re: Compare two array value
Jump_Over Nov 24, 2014 12:27 AM (in response to creativejoan0425)Hi,
Remove "var" at line 14
1,5,6 on my side...
Jarek


