title: Add elements inside Array conditionally in JavaScript
body: <p>When I try to merge two objects using the spread operator conditionally, it works when the condition is <code>true</code> or <code>false</code>:</p>
  
  <pre><code>let condition = false;
  let obj1 = { key1: 'value1'}
  let obj2 = {
    key2: 'value2',
    ...(condition &amp;&amp; obj1),
  };
  
  // obj2 = {key2: 'value2'};
  </code></pre>
  
  <p>When I try to use the same logic with Arrays, it only works when the condition is <code>true</code>:</p>
  
  <pre><code>let condition = true;
  let arr1 = ['value1'];
  let arr2 = ['value2', ...(condition &amp;&amp; arr1)];
  
  // arr2 = ['value2', 'value1']
  </code></pre>
  
  <p>If the condition is <code>false</code> an error is thrown:</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>let condition = false;
  let arr1 = ['value1'];
  let arr2 = ['value2', ...(condition &amp;&amp; arr1)];
  
  // Error</code></pre>
  </div>
  </div>
  </p>
  
  <p>Why is the behaviour different between <code>Array</code> and <code>Object</code>?</p>