i have three array of objects like arr_1,arr_2 and arr_3 and i tried to merge all this three objects together but i am not getting what i try to want
const arr_1 = [
{"user_id": "3","user_name": "Jack"},
{ "user_id": "4", "user_name": "Doe"}
];
const arr_2 = [
{"user_id": "3","address": "New York" },
{"user_id": "3","address": "California"},
{"user_id": "4", "address": "Miami"},
{ "user_id": "4","address": "Turkey"}
];
const arr_3 = [
{ "user_id": "3","category_id": "3"},
{"user_id": "3", "category_id": "4" },
{ "user_id": "4","category_id": "6" },
{ "user_id": "4","category_id": "7"}
];
const result = [
{ "user_id": 3,"user_name": "Jack",
"address": ["New York","California"],
"category_id": ["3","4"]
},
{ "user_id": 4, "user_name": "doe",
"address": ["Miami", "Turkey"],
"category_id": ["6","7"]
},
]
result= [
{ "user_id": 3,"user_name": "Jack",
"address": "New York",
"category_id": "3"
},
{ "user_id": 4,"user_name": "doe",
"address": "Miami",
"category_id": "6"
},
]
What I have tried:
const result = arr_1.map(t1 =>
({...t1, ...arr_2.find(t2 => t2.user_id === t1.user_id),
...arr_3.find(t3=> t3.user_id=== t1.user_id)
}))