title: Javascript map with index to json
body: <p>I have an array of images</p>
  
  <pre><code>[ "foto7.jpg", "foto3.jpg", "foto5.jpg"]
  </code></pre>
  
  <p>I'm trying to shuffle it and then map it to an hash with a predefined structure.
  My function now is (vue computed properties)</p>
  
  <pre><code>randomDataset: function () {
        var array = this.shuffleArray(this.images)
        return array.map((currElement, index) =&gt; {
          var hash = {};
          hash['reference']= index+1;
          hash['image']= currElement
          return hash
        });
  
      }
    }
  </code></pre>
  
  <p>and the output is</p>
  
  <pre><code>[ { "reference": 1, "image": "foto8.jpg" }, { "reference": 2, "image": "foto6.jpg" }..] 
  </code></pre>
  
  <p>I cannot find a way to have a structure like this</p>
  
  <pre><code>{
    "images": {
      "1": {
        "image_url": "www....",
        "image_reference": "1"
      },
      "2": {
        "image_url": "www....",
        "image_reference": "2"
      }
    }
  }
  </code></pre>
  
  <p>The numbers (1,2...etc) are the index of the array I'm mapping, and the image url is the array value. How can I do?</p>