```js

[
  {
    "id": 3401,
    "league": {
      "id": 4140,
      "image_url": "pngurl.png",
      "modified_at": "2019-02-19T15:29:07Z",
      "name": "League Cup",
      "slug": "league-slug",
      "url": null
    }
  }
]

```

I have a lot of such objects in the array. How can I sort/format my array such way I got a new array/dictionary with objects sorted by value of `"id"` in `"league"` from example it's `4140`. Now i have a normal array but I want something sorted either by key-value something like 4140: [objects from array with league id 4140] or 2d array sorted `[[array with all objects containing league with value "id" of 4140], [array with objects with league value id 4141], etc..]`. Do i need to use `map` or something like that ? I am pretty new to Javascript.

Here is what I expect to get in code.

```js
//THIS is what I want to get in the end...
[
  {
    "league": "League Cup",
    "tournaments": [
      {
        "id": 3402,
        "league": {
          "id": 4141,
          "image_url": "pngurl.png",
          "modified_at": "2019-02-19T15:29:07Z",
          "name": "League Cup",
          "slug": "league-slug",
          "url": null
        }
      },
      {
        "id": 3403,
        "league": {
          "id": 4141,
          "image_url": "pngurl.png",
          "modified_at": "2019-02-19T15:29:07Z",
          "name": "League Cup",
          "slug": "league-slug",
          "url": null
        }
      }
    ]
  },
  {
    "league": "League Cup 2",
    "tournaments": [
      {
        "id": 3401,
        "league": {
          "id": 4145,
          "image_url": "pngurl.png",
          "modified_at": "2019-02-19T15:29:07Z",
          "name": "League Cup 2",
          "slug": "league-slug",
          "url": null
        }
      },
      {
        "id": 3405,
        "league": {
          "id": 4145,
          "image_url": "pngurl.png",
          "modified_at": "2019-02-19T15:29:07Z",
          "name": "League Cup 2",
          "slug": "league-slug",
          "url": null
        }
      }
    ]
  }
]

```