How can I merge more than two array of objects into one array of objects. Like I have:
var arr1 = [{"userID": 554,"name":"abc"},{"userID": 555,"name":"xyz"}]
var arr2 = [{"userID": 554,"lang":"ENG"},{"userID": 554,"lang":"GER"},{"userID": 555,"lang":"ENG"}]
var arr3 = [{"userID": 554,"SET":"QWE"},{"userID": 555,"SET":"ABC"},{"userID": 555,"SET":"XYZ"}]
Now I want to merge all these into one by the same key value i.e., userID, so my final output should be like
var final = [
{
"name":"abc"
"userID": 554,
"arr2" = [
{
"userID": 554,
"lang":"ENG"
},
{
"userID": 554,
"lang":"GER"
}
],
"arr3" = [
{
"userID": 554,
"SET":"QWE"
}
]
},
{
"userID": 555,
"name":"xyz"
"arr2" = [
{
"userID": 555,
"name":"ENG"
}
],
"arr3" = [
{
"userID": 555,
"SET":"ABC"
},
{
"userID": 555,
"SET":"XYZ"
}
]
}
]
I can't user ES6 with Spread operator (...) as I have a condition that it should be merged in the array where the key userID
matches so that I gets the above output or like {"userID": 554, "name": "abc", "lang": ["ENG", "GER"],...}