The solution involves giving separate names to the first and second arrays, and then using the common key to link them together. In the code example provided, the first array is called "FirstQuery.data" and the second array is called "SecondQuery.data". The common key is "id", which is used to filter the second array to only include items that match the "id" of the item in the first array.
To achieve this, the code uses the map function to iterate over each item in the first array and create an object with its properties. The second array is then filtered to only include items that have a matching "x_id" property and mapped to an array of objects with their respective properties. Finally, the object for each item in the first array includes the filtered array of objects from the second array that are linked by the common key.
Overall, this allows for dynamically linking the two arrays based on a common key and nesting them together in a way that only includes data related to the first array item.