title: How can I get the array outside the function?
body: <pre><code>$("#div").click(function(){
   $('#myselect').change(function() {
       var names = [];
       $('.checkbox input').each(function() {
             if(this.value != ''){
                   names.push(this.value);
                  }
               });
       console.log(names);
    });
  });
  </code></pre>
  
  <p>I need to use the <code>names</code> outside that function to use it on another function. Can anyone tell me how to do it?</p>
  
  <pre><code>$("#dropdown").change(function(){
    console.log(names);
  });
  </code></pre>
  
  <p><code>names</code> is an array.</p>