I have two arrays A, B with objects from the database. I want to merge the objects from array B into array A that have a relation: (A[n].id == B[n].a_id).
const array_a = [
{
"id": 4,
"status": 0,
},
{
"id": 5,
"status": 1,
}
];
const array_b = [{
active: 1,
a_id: 5, // SELECTOR FOR MERGE
created_at: '2022-11-05 20:29:29',
firstname: 'user3',
lastname: ''
}];
Expected result:
const result = [
{
"id": 4,
"status": 0,
},
{
"id": 5,
"status": 1,
"active": 1,
"user_id": 5,
"created_at": '2022-11-05 20:29:29',
"firstname": 'user3',
"lastname:" ''
}
];
I tried this approach from another SO answer and got nowhere.
https://stackoverflow.com/a/53462680/18066399 :-/