my global variable wont work

my global variable wont work

    //when i console array variable row in the second click handler its displayed as undefined.

    $(document).ready(function(){
       
         var row = [];
       
        $('tr').click(function(){
             $tds = $(this).find("td");             // Finds all children <td> elements
       
              $.each($tds, function(index) {               // Visits every single <td> element
                
                      row[index] = $(this).text();
                     
              });// end loop
             
            
       
              console.log(row[6]); // now row[6] contains a unique id
         
            $('#myModalLabel'+row[6]).text(row[0]);
       
       
          });
        //'#'+row[6] is a button inside a modal...the modal popup whenever a tr is clicked..row[6] contains a unique id..please note the table is generated dynamically using php

        $('#'+row[6]).click(function(){
       

      

         console.log(row[6]);// shows undefined.
    
                           
                  
       
                       
       
       
        });




                 




       
    });