title: How do rearrange the nested array
body: <p>Below is my response which is getting from the MySQL database,</p>
  <p>I want to rearrange childInterest like in the second desired output</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"childInterest": [
          {
            "id": 1,
            "parentInterestId": 3,
            "created_at": "2022-03-04T07:30:31.851Z",
            "updated_at": "2022-03-04T07:30:31.851Z",
            "interest": {
              "id": 6,
              "interestId": 3,
              "name": "collecting stamps",
              "level": 2,
              "createdAt": "2022-01-27T14:22:22.586Z",
              "updatedAt": "2022-01-27T14:22:22.586Z",
              "heirarchy": {
                "id": 3,
                "interestId": null,
                "name": "hobbies",
                "level": 1,
                "createdAt": "2022-01-27T14:20:40.362Z",
                "updatedAt": "2022-01-27T14:20:40.362Z"
              }
            }
          },
          {
            "id": 2,
            "parentInterestId": 3,
            "created_at": "2022-03-04T07:30:31.863Z",
            "updated_at": "2022-03-04T07:30:31.863Z",
            "interest": {
              "id": 7,
              "interestId": 3,
              "name": "chess play",
              "level": 2,
              "createdAt": "2022-01-27T14:22:48.734Z",
              "updatedAt": "2022-01-27T14:22:48.734Z",
              "heirarchy": {
                "id": 3,
                "interestId": null,
                "name": "hobbies",
                "level": 1,
                "createdAt": "2022-01-27T14:20:40.362Z",
                "updatedAt": "2022-01-27T14:20:40.362Z"
              }
            }
          },
          {
            "id": 5,
            "parentInterestId": 4,
            "created_at": "2022-03-04T08:06:03.499Z",
            "updated_at": "2022-03-04T08:06:03.499Z",
            "interest": {
              "id": 8,
              "interestId": 4,
              "name": "cricket",
              "level": 2,
              "createdAt": "2022-01-27T14:23:13.042Z",
              "updatedAt": "2022-01-27T14:23:13.042Z",
              "heirarchy": {
                "id": 4,
                "interestId": null,
                "name": "outdoor",
                "level": 1,
                "createdAt": "2022-01-27T14:21:00.701Z",
                "updatedAt": "2022-01-27T14:21:00.701Z"
              }
            }
          },
          {
            "id": 6,
            "parentInterestId": 4,
            "created_at": "2022-03-04T08:06:03.519Z",
            "updated_at": "2022-03-04T08:06:03.519Z",
            "interest": {
              "id": 9,
              "interestId": 4,
              "name": "coco",
              "level": 2,
              "createdAt": "2022-01-27T14:23:22.940Z",
              "updatedAt": "2022-01-27T14:23:22.940Z",
              "heirarchy": {
                "id": 4,
                "interestId": null,
                "name": "outdoor",
                "level": 1,
                "createdAt": "2022-01-27T14:21:00.701Z",
                "updatedAt": "2022-01-27T14:21:00.701Z"
              }
            }
          }
        ],</code></pre>
  </div>
  </div>
  </p>
  <p>And I want a response like below</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  "childInterest": [
        {
          title: "Hobbies",
          titleitems: [
            "Music",
            "Video"
          ]
        },
        {
          title: "Indoor",
          titleItems: [
            "Carrom",
            "Table Tenis"
          ]
        },
        {
          title: "Outdoor",
          titleItems: [
            "Cricket",
            "Kabbadi"
          ]
        }
      ]
    }
    ],
  
  
  In 1st array whatever names hobbies, outdoor is there should come under single object inside that array should hobbies names like music video etc.</code></pre>
  </div>
  </div>
  </p>