title: Javascript cannot set property 0 of undefined
body: <p>This code generates error:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot set property '0' of undefined</p>
  </blockquote>
  
  <p>While I want to assign random numbers in array, please help.   </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 array;
  for (var i = 1; i &lt; 10; i++) {
    array[i] = Math.floor(Math.random() * 7);
  }
  console.log(array);</code></pre>
  </div>
  </div>
  </p>