title: JavaScript Check multiple variables being empty
body: <p>I'm trying the following code:</p>
  
  <pre><code>var var1 = "";
  var var2 = "test";
  var var3 = "";
  
  vars = new Array('var1','var2','var3');
  
  var count = 0;
  
  for (var i = 0; i &lt; vars.length; ++i) {
      var name = vars[i];
      if (field_is_empty(name)) {
          count++;
      }
  }
  
  console.log(count);
  
  function field_is_empty(sValue) {
      if (sValue == "" || sValue == null || sValue == "undefined")
      {
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>The result here should have been <code>count = 2</code> because two of the variables are empty but it's always <code>0</code>. I guess it must something when using <code>if (field_is_empty(name))</code> because it might not getting the name converted to the name of the actual var.</p>
  
  <p><strong><em>PROBLEM 2# Still related</em></strong></p>
  
  <p>I've updated the code as <strong>Karthik Ganesan</strong> mentioned and it works perfectly.</p>
  
  <p>Now the code is:</p>
  
  <pre><code>var var1 = "";
  var var2 = "test";
  var var3 = "";
  
  vars = new Array(var1,var2,var3);
  
  var count = 0;
  
  for (var i = 0; i &lt; vars.length; ++i) {
      var name = vars[i];
      if (field_is_empty(name)) {
          count++;
      }
  }
  
  console.log(count);
  
  function field_is_empty(sValue) {
      if (sValue == "" || sValue == null || sValue == "undefined")
      {
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>And the problem is that if add a new if statement something like this:</p>
  
  <pre><code>if (count == '3') {
      console.log('AllAreEmpty');
  } else {
      for (var i = 0; i &lt; vars.length; ++i) {
          var name = vars[i];
          if (field_is_empty(name)) {
              //Set the empty variables as "1900-01-01"
              variableService.setValue(name,"test");
          }
      }
  }
  </code></pre>
  
  <p>It does nothing and I've tested using <code>variableService.setValue('var1',"test")</code> and it works.</p>
  
  <p>PS: The variableService.setValue is a function controlled by the software I don't know exactly what it does I know if use it like mentioned on above line it works.</p>