title: Convert js Array to Dictionary/Hashmap
body: <p>I'm trying to convert an array of objects into a hashmap. I only have some parts of ES6 available and I cannot use <code>Map</code> as well.</p>
  
  <p>The objects in the array are quite simple, e.g. <code>{nation: {name: string, iso: string, scoringPoints: number}</code>. I need to sort them by <code>scoringPoints</code>.
  I want now a "dictionary" holding the rank by iso -> <code>{[iso:string]:number}</code>.</p>
  
  <p>I already tried (from <a href="https://stackoverflow.com/a/48671992/615288">here (SO)</a>)</p>
  
  <pre><code>const dict = sortedData.reduce((prev, curr, index, array) =&gt; (
      { ...array, [curr.nation.iso]: ++index }
  ), {});
  </code></pre>
  
  <p>But <code>dict</code> turns out to be an <code>Object</code> with indices starting with <code>0</code>. Hopefully there is just a small thing I don't see. But currently my head is spinning how to convert a simple array into a hashmap-like object.
  Maybe <code>Array.map</code>?</p>
  
  <p>I should also note that I am using <code>TypeScript</code> which I also had some trouble before when not typed correctly.</p>
  
  <pre><code>const test = [
      { nation: { name: "Germany", iso: "DE", rankingPoints: 293949 } },
      { nation: { name: "Hungary", iso: "HU", rankingPoints: 564161 } },
      { nation: { name: "Serbia", iso: "SR", rankingPoints: 231651 } }
  ];
  
  const sorted = test.sort((a, b) =&gt; a.nation.rankingPoints - b.nation.rankingPoints);
  const dict = sorted.reduce((prev, curr, index, array) =&gt; ({ ...array, [curr.nation.iso]: ++index }), {});
  console.log(JSON.stringify(dict));  
  </code></pre>
  
  <p>is showing</p>
  
  <pre><code>{
      "0": {
          "nation": {
              "name": "Serbia",
              "iso": "RS",
              "rankingPoints": 231651
          }
      },
      "1": {
          "nation": {
              "name": "Germany",
              "iso": "DE",
              "rankingPoints": 293949
          }
      },
      "2": {
          "nation": {
              "name": "Hungary",
              "iso": "HU",
              "rankingPoints": 564161
          }
      },
      "HU": 3
  }
  </code></pre>
  
  <p>in the console.</p>
  
  <p>As per comments, what I want is a hashmap-like object like</p>
  
  <pre><code>{
      "HU": 1,
      "DE": 2,
      "RS": 3
  }
  </code></pre>
  
  <p>where the property-value is the rank (+1) in the sorted data so I can simply get the rank by accessing <code>dict["DE"]</code> which would return <code>2</code>.</p>