title: variables in jquery each function
body: <p>can anybody help me ? - ></p>
  
  <p>I wont that vars id,zIndex,width  inside function after jQuery.each will be defined
  and their values will be values from array passed to function MyFunction:</p>
  
  <pre><code>console.log(id);  //ID IS NOT DEFINED  
  console.log(zIndex);  //NOT DEFINED  
  console.log(width);  //NOT DEFINED
  </code></pre>
  
  <p>many thanks for help, Peter</p>
  
  <p>Code></p>
  
  <pre><code>var MyArray = new Object();
  MyArray.id = "3";
  MyArray.zIndex = "3";
  MyArray.width = "600";
  
  function MyFunction(my_array) {
  
  console.log(my_array.id);  //IT IS OK, id is defined    
  
  jQuery.each(my_array, function(key,value) {
      alert(key + " = " + value);
      eval("var" + key + " = " + value); //??????? 
  
  
  });
  
  console.log(id);  //ID IS NOT DEFINED
  console.log(zIndex);  //NOT DEFINED
  console.log(width);  //NOT DEFINED
  
  }
  
  MyFunction(MyArray);
  </code></pre>
  
  <p>-----UPDATED ----------------------</p>
  
  <p>THANKS ALL FOR ANSWER 
  IN THE MEANTIME I UPDATED MY CODE, 
  I WONT TO CREATE SMALL PLUGIN FOR MY APPLICATION<br>
  METHOD OPENWINDOW IS PUBLIC</p>
  
  <p>MY QUESTION IS HOW CAN I USE METHOD </p>
  
  <pre><code>jQuery.each(my_array, function(key,value) {
   window[key]=value;
  });
  </code></pre>
  
  <p>IN PLUGIN PUBLIC METHOD OPENWINDOW</p>
  
  <p>HERE IS CODE IN MORE COMPLEX:</p>
  
  <pre><code>    (function($){
      $.fn.MyPlugin = function(options) {
  
              ...... CODE
  
              this.OpenWindow = function(my_array) {
  
              //this way dont work for me here, vars are not defined
              var window = $(window);
                      jQuery.each(my_array, function(key,value) {
                  window[key]=value;
              });
  
  
                      //VARS ARE NOT DEFINED
                      console.log(id); 
              console.log(zIndex);
              console.log(width);
  
  
                 //this way work well
                  for (var k in my_array){
                      eval ("var " + k + " = " + my_array[k]);
                  }
  
                          //VARS ARE DEFINED
                  console.log(id); 
                  console.log(zIndex);
                  console.log(width);
  
  
              .... code
  
       return this;
      };
      })(jQuery);
  
  var MyArray = new Object();
  MyArray.id = "3";
  MyArray.zIndex = "3";
  MyArray.width = "600";
  
  
  var MyPlugin = $.fn.MyPlugin();
  MyPlugin.OpenWindow(MyArray);
  </code></pre>