I have an array of attendees, 2 of them are also instructors. I want to update one of the instructors by replacing him/her and leave the remaining attendees intact in the array.
Here's an example:
{
attendees: [
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' }
]
}
Now I submit a new array of instructors with one of them changed:
{
instructors: [
{ email : '[email protected]' },
{ email : '[email protected]' }
]
}
And my final result should be:
{
attendees: [
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' }
]
}
Where [email protected] has replaced [email protected] as the new instructor. I think I can use _.differenceBy with lodash but can't figure out how to replace the changed element in the array. Is there an elegant way to do this?
Array#concat(Array)id, where they can be identified with and matched across the 2 arrays.