title: How to merge two objects based on id and group same key value pairs
body: <pre><code>      var routePlan = [
        {
          "id" : 1,
          "farmerName" : "Farmer1",
          "farmerId" : 1
        },
        {
          "id" : 2,
          "farmerName" : "Farmer2",
          "farmerId" : 2
        },
        {
          "id" : 1,
          "farmerName" : "Farmer3",
          "farmerId" : 3
        }
      ];
  </code></pre>
  
  <p>I want to merge objects having same id and create a new combined object using javascript or angularjs</p>
  
  <pre><code>      var routePlan = [
        {
          "id" : 1,
          "farmers" : [
            {
              "farmerName" : "Farmer1",
              "farmerId" : 1
            },
            {
              "farmerName" : "Farmer3",
              "farmerId" : 3
            }
          ]
        },
        {
          "id" : 2,
          "farmerName" : "Farmer3",
          "farmerId" : 2
        }
      ];
  </code></pre>
  
  <p>Please help me, I have seen lot of examples on the net but nothing seems to match my requirement</p>