SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: compare arrays

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Uruguay
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    compare arrays

    Hi
    I have 2 arrays with thises values:

    province =[5,5,5,8]
    city=[1,1,3,7]

    If you see careful, on index 0 y 1 from both arrays they have the same values: 5, 5 y 1,1

    How can I detect the repetition???
    I want to detect when province has 5,5 (the same numbers), and city array two equal values too (here 1,1).

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Western Europe
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this?

    if (province[0] == province[1]) {
    // do something
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've seen prototypes for this. Try searching for "Array.prototype"

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Uruguay
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry guys, I didn´t explain it in detail.

    I have the "parent" array called province, and its child city. province must have just one child with the same value. I know that city value 2 is child of province value 5, so province must have only one city[2], not more.
    I the user "selects" two, an alert have to run when user submit.

    this is the function wich creates the arrays:

    Code:
    function Values(form1){
                frm = document.forms[0];
                province = [];
                city = [];
    
                total_selects=document.forms["form1"].getElementsByTagName("select").length/2;
    			
                for(i=1;i<=total_selects;i++){             
                        if(eval("document.getElementById('province"+i+"').value==0")){
                            alert("Provincia está vacio");
                            return false; 
                        }else{
                            province.push(eval("document.getElementById('province"+i+"').value"));// to fill the array province
                        }
                        
                        if(eval("document.getElementById('city"+i+"').value==0")){
                            alert("Ciudad está vacio");
                            return false; 
                        }else{
                            city.push(eval("document.getElementById('city"+i+"').value"));// to fill the array city 
                        }
                }
        
                document.form1.province.value = province; //here are both arrays
                document.form1.city.value = city;
                
            }
    thanks!!

Bookmarks

Posting Permissions

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