I have 2 arrays, and I try to merge the 2 arrays based on their id, and the sequence of the array must be same as the first array
array1: [
{id: student1, name: 'Jacky', course: ''},
{id: student2, name: 'Taylor', course: ''},
{id: student3, name: 'David', course: ''},
{id: student4, name: 'Aisy', course: ''},
{id: student5, name: 'Micky', course: ''}
];
and
array2: [
{id: student1, name: 'Jacky', course: 'science'},
{id: student2, name: 'Taylor', course: 'biology'},
{id: student1, name: 'Jacky', course: 'math'},
{id: student4, name: 'Aisy', course: 'chemistry'},
{id: student1, name: 'Jacky', course: 'history'},
];
I want the result be like
array:[
{id: student1, name: 'Jacky', course: 'science'},
{id: student1, name: 'Jacky', course: 'math'},
{id: student1, name: 'Jacky', course: 'history'},
{id: student2, name: 'Taylor', course: 'biology'},
{id: student3, name: 'David', course: ''},
{id: student4, name: 'Aisy', course: 'chemistry'},
{id: student5, name: 'Micky', course: ''}
];