title: Conditional Array in Javascript
body: <p>code1, code2 and Code3 are constant whereas code1quantity,code2quantity values are from screen</p>
  
  <p>if i dont get value for quantity, then code also should not be added to the array</p>
  
  <p>Condition 1:</p>
  
  <pre><code>var Code1  = 'xyz';
  var Code2  = 'abc';
  var Code3  = 'mno';
  
  var Code1Quantity  = 1;
  var Code2Quantity  = 2;
  var Code3Quantity  = 3;
  
  var data = {
         Codes :  [{'code':Code1,'Quantity':Code1Quantity},
                   {'code':Code2,'Quantity':Code2Quantity},
                   {'code':Code3,'Quantity':Code3Quantity}
                 ]
               }
  </code></pre>
  
  <p>Condition 2 needs to be achieved:</p>
  
  <pre><code>var Code1  = 'xyz';
  var Code2  = 'abc';
  var Code3  = 'mno';
  
  var Code1Quantity  = 1;
  var Code2Quantity  = 0;
  var Code3Quantity  = 1;
  
  var data = {
         Codes :  [{'code':Code1,'Quantity':Code1Quantity},
                   {'code':Code3,'Quantity':Code3Quantity}
                 ]
               }
  </code></pre>
  
  <p>if Code2Quantity  is zero we should not add the code2 too, as the code quantity values are chosen from the screen, it may or may not have values</p>
  
  <p>how it can be achieved?</p>