title: How to check if all array elements which are ids of html elements has value
body: <p>I am receiving <code>id</code>s of required html <code>input</code>s in an array through ajax. Here is my HTML:</p>
  
  <pre><code>&lt;form&gt;
    &lt;input type="text" id="firstName" placeholder="First Name"&gt;
    &lt;input type="text" id="lastName" placeholder="Last Name"&gt;
    &lt;input type="email" id="email" placeholder="Email"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is the required ids:</p>
  
  <pre><code>var arr = ['firstName', 'email'];
  </code></pre>
  
  <p>My goal is to check if all required input has value or not. So, I have written:</p>
  
  <pre><code>var areSomeFieldsEmpty = false;
  
  function checkForm() {
    $.each(arr, function(index, value){
      if($('#' + value).val().length &lt;= 0) {
        areSomeFieldsEmpty = true;
      } else {
        areSomeFieldsEmpty = false;
      }
    });
  </code></pre>
  
  <p>But, by keeping <code>firstName</code> input empty, if I put value on <code>email</code> input, I got <code>false</code> as a value of <code>areSomeFieldsEmpty</code>. But, it should be <code>true</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/jXpIE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jXpIE.png" alt="enter image description here"></a></p>
  
  <p>How to fix this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var arr = ['firstName', 'email'];
  
  $('form').on('keyup blur change', 'input', function() {
   checkForm();
  });
  var areSomeFieldsEmpty = false;
  
  function checkForm() {
    $.each(arr, function(index, value){
      if($('#' + value).val().length  &lt;= 0) {
        areSomeFieldsEmpty = true;
      } else {
        areSomeFieldsEmpty = false;
      }
    });
  
    console.log(areSomeFieldsEmpty);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form&gt;
    &lt;input type="text" id="firstName" placeholder="First Name"&gt;
    &lt;input type="text" id="lastName" placeholder="Last Name"&gt;
    &lt;input type="email" id="email" placeholder="Email"&gt;
  &lt;/form&gt;
  
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>