javascript – Node.js – How to merge objects inside an array based on condition?

In Node.js, I have 3 sets of data like

[
    {
        "userId":"54c7f3ef-64d4-40de-8100-d2ec81e8aaf3",
        "dailyData":159392.235451,
        "dailyDataInUSC":255.284807
    }
] 

and

[
    {
        "userId":"54c7f3ef-64d4-40de-8100-d2ec81e8aaf3",
        "monthlyData":159392.235451,
        "monthlyDataInUSC":255.284807
    }, 
    {
        "userId":"23fs6fds3-34k4-17de-3123-d2ec81e8aaf3",
        "monthlyData":349392.455451,
        "monthlyDataInUSC":655.234807
    }
] 

and

[
    {
        "userId":"54c7f3ef-64d4-40de-8100-d2ec81e8aaf3",
        "threeMonthsData":159392.235451,
        "threeMonthsDataInUSC":255.284807
    }, 
    {
        "userId":"23fs6fds3-34k4-17de-3123-d2ec81e8aaf3",
        "threeMonthsData":349392.455451,
        "threeMonthsDataInUSC":655.234807
    }, 
    {
        "userId":"34sdf34-67j4-54nd-6763-d2ec81e8aaf3",
        "threeMonthsData":6789392.455451,
        "threeMonthsDataInUSC":905.655807
    }
] 

How can I combine this to one object based on userId(filter) inside an array.

Eg, output should be like

[
    {
        "userId":"54c7f3ef-64d4-40de-8100-d2ec81e8aaf3",
        "dailyData":159392.235451,
        "dailyDataInUSC":255.284807,
        "monthlyData":159392.235451,
        "monthlyDataInUSC":255.284807,
        "threeMonthsData":159392.235451,
        "threeMonthsDataInUSC":255.284807
    }
]

Please help me to achieve this.

Read more here: Source link