Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Duplicate checking in an Array. please help

    I am new to JavaScript programming. Could any one help me in solving this problem? My problem is to find the duplicate value in the array.

    I have a single dimension array with the following data stored on it.

    a[0] = 1~1~10
    a[1] = 1~2~11
    a[2] = 1~3~15
    a[3] = 1~4~19
    a[5] = 1~6~10

    Here in my case a[0] and a[5] is duplicate because i am using 1 or 0 for active and deactivate purpose a[4] is deactivate value so we can ignore the 10 in this. so in my case 10 is repeated twice on a[0]and a[5] not a[4], so its duplicate value. can any one help me to solve this.
    Thanks you.
    wowrang.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,501
    Thanks
    3
    Thanked 500 Times in 487 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    var a=[];
    a[0] = '1~1~10'
    a[1] = '1~2~11'
    a[2] = '1~3~15'
    a[3] = '1~4~19'
    a[5] = '1~6~10'
    var mtch='';
    var ary=[];
    for (var zxc0=0;zxc0<a.length;zxc0++){
     if (a[zxc0]){
      var key=a[zxc0].split('~')[2];
      if (!mtch.match(key)){
       mtch+=key+'~';
       ary.push(a[zxc0]);
      }
     }
    }
    alert(ary.join(','));
    /*]]>*/
    </script></body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks alot vwphillips for you time. problem resolved


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •