title: Create a new map from an array of object with similar id in Typescript
body: <p>I'm trying to create a map> from a list of objects that have similar ids in typescript, but I don't get the correct way to do. I know that in lodash something like so is doable but can't get it to work. This what I have tried</p>
  
  <p>let's say I have list of colors like so: </p>
  
  <pre><code> [
      {
          "Id": "1",
          "color": "red",
          "ref": "tr"
      },
      {
          "Id": "1",
          "color": "blue",
          "ref": "gt",
      },
      {
          "Id": "2",
          "color": "red",
          "ref": "tt"
      },
   ]
  </code></pre>
  
  <p>I'm trying to construct a map like so</p>
  
  <pre><code>[
    1: [
        {
          "Id": "1",
          "color": "red",
          "ref": "tr"
        },
        {
          "Id": "1",
          "color": "blue",
          "ref": "gt",
        }
       ],
    2: [
        {
          "Id": "2",
          "color": "red",
          "ref": "tt"
        }
       ]
  ]
  </code></pre>
  
  <p>this is what I tried so far:</p>
  
  <pre><code>const colorsMap: Map&lt;string, Array&lt;Color&gt;&gt; = new Map&lt;string, Array&lt;Color&gt;&gt;();
  let colorLists: Array&lt;Color&gt; = [];
  colors.forEach(function (value, i) {
              if (value[i - 1]) {
                  if (colors[i - 1].id=== value.gblId) {
                      const color = new Color(value.styleId, value.color, value.ref);
                      colorLists.push(gblRowValue);
                  } else {
                      const color = new Color(value.styleId, value.color, value.ref);
                      colorLists= new Array&lt;Color&gt;();
                      colorLists.push(color);
                  }
              }
              colorsMap.set(value.id, colorLists);
          });
  </code></pre>
  
  <p>The result is in each array I get only one value: </p>
  
  <pre><code>    [
        1: [
            {
             "Id": "1",
             "color": "blue",
             "ref": "gt",
            }
           ],
        2: [
            {
             "Id": "2",
             "color": "red",
             "ref": "tt"
            }
           ]
       ]
  </code></pre>