Making one to many relation array in JavaScript
<p>I have two arrays of objects: </p>

<pre><code>var a = [{
  "id": 1,
  "name": "q"
},
{
  "id": 2,
  "name": "l"
}]
</code></pre>

<p>and another is</p>

<pre><code>var b = [{
  "id": 3,
  "sub": 1,
  "name": "ni"
},
{
  "id": 4,
  "sub": 2,
  "name": "bh"
}]
</code></pre>

<p>Here sub is the id in <code>a</code></p>

<p>I need to have a new array which will look like this:</p>

<pre><code>var c = [
  {
    "id":1,
    "name":"q",
    "map":[
      {
        "id":3,
        "name":"ni"
      }
    ]
  },
  {
    "id":2,
    "name":"l",
    "map":[
      {
        "id":4,
        "name":"bh"
      }
    ]
  }
]
</code></pre>

<p>How can I do that in JavaScript?</p>

<p>I am using underscore in my project.</p>