title: JS: Assign variable value inside for loop depending on condition
body: <p>I need to add </p>
  
  <pre><code>if (obj1[i][0] !== d1 &amp;&amp; row &gt; -1) continue;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>if (obj1[i][1] !== d2 &amp;&amp; row &gt; -1) continue;
  </code></pre>
  
  <p>depending on the value of <code>d1 and d2</code> but I'm not sure what I'm doing wrong.</p>
  
  <p><code>if</code> statement acts as a filter it will allow only those values which assigned to <code>d1</code> or <code>d2</code> e.g if <code>d1=1</code> it will print only values with 1 and not all values in the table.  </p>
  
  <pre><code>$("#session_id, #start_date").on('change', function() {
      var d1 = $( "#session_id" ).val();
      var d2 = $( "#start_date" ).val();
  
      $("#tbody").empty();
  
  
      if(d1 != null || d1 != undefined){
          kl1 = "if (obj1[i][0] !== d1 &amp;&amp; row &gt; -1) continue;";
          v(kl1);
      }
  
      if(d2 != null || d2 != undefined){
          var kl = "if (obj1[i][1] !== d2 &amp;&amp; row &gt; -1) continue;"
          v(kl);
      }
  
      function v(data){
          for (var i = 0; i &lt; obj1.length; i++) {
                  data;
              row++;
          var newTr = table.insertRow(-1);
          newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][1]));
          newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][2]));
          newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][3]));
          newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][4]));
          newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][5]));
      }
  }
  });
  </code></pre>