title: How to create a list of objects in JavaScript
body: <p>I have an array of pairs of values somewhat like this:</p>
  
  <pre><code> let myarr = [[1, 'a'],
                [2, 'b'],
                [3, 'c']] 
  </code></pre>
  
  <p>and one like this:</p>
  
  <pre><code>let otherArr = [5,6,7]
  </code></pre>
  
  <p>and I would like to convert them to an object which would be of the form:</p>
  
  <pre><code>{
     "data":[
        {
           "id":5,
           "pair":[
              1,
              "a"
           ]
        },
        {
           "id":6,
           "pair":[
              2,
              "b"
           ]
        },
        {
           "id":7,
           "pair":[
              3,
              "c"
           ]
        }
     ]
  }
  </code></pre>
  
  <p>As a first attempt </p>
  
  <p>I tried to use a <code>for</code> loop and tried to create a list of the <code>pair</code> keys like this</p>
  
  <pre><code>for (let pair = 0; pair &lt; myarr.length; pair++) {
    myobj[pair].pair = myarr[pair]
  </code></pre>
  
  <p>and I get an error stating <code>TypeError: Cannot set property 'pair' of undefined</code></p>
  
  <p>Is there a efficient way to create a object like the example above
  Thanks in advance</p>