title: Creating an array of objects with for loop in JavaScript
body: <p><strong>I want to create an array of objects with <code>for</code> loop using values in another array.</strong></p>
  
  <p><em>Code Snippet below</em> generates <code>5</code> values, instead of <code>6</code> (as required) </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>function generateArray() {
      var names = ["Fariz", "Falisha", "Mami", "Defina", "Fiska", "Papi"];
      var newObj = [];
  
      for (i = 0; i &lt; names.length - 1; i++) {
          newObj[i] = {
              name: names[(Math.floor(Math.random() * (names.length)))],
              age: Math.floor(Math.random() * 40),
              communication: Math.floor(Math.random() * 20),
              skill: Math.floor(Math.random() * 20),
              experience: Math.floor(Math.random() * 20)
          }
      }
  
      return newObj;
  }
  
  console.log(generateArray());</code></pre>
  </div>
  </div>
  </p>
  
  <blockquote>
    <p><strong>How do I generate as many values as present in <code>names</code> array ?</strong></p>
  </blockquote>