Currently, I am facing a challenge while working on this problem using Typescript. It has been quite some time since I started working on it and I am hoping that the helpful community at StackOverflow could provide assistance :)
The scenario involves two array structures:
var localUsers = [{
firstName: "Joe",
lastName: "Bloggs",
id: "44c021ab-be92-409b-99ad-4c3fe61d894a"
}, {
firstName: "Pete",
lastName: "Doe",
id: "017b4dab-d58b-475e-ab31-6363d9de25c0"
}, {
firstName: "Andy",
lastName: "NotRemote",
id: "2233e4cb-d324-463d-9a42-24b1b4cd3e11"
}]
//The above array is used for a database lookup
var remoteUsers = [{
id: "44c021ab-be92-409b-99ad-4c3fe61d894a",
timestamp: "2017-07-01T12:00:00.000"
}, {
id: "017b4dab-d58b-475e-ab31-6363d9de25c0",
timestamp: "2017-07-01T13:30:00.000"
}]
I am looking to merge these arrays based on the id
key. All keys in remoteUsers
will have a matching entry in localUsers
, but the reverse may not always be true. The desired output should resemble the following:
var allUsers = [{
firstName: "Joe",
lastName: "Bloggs",
id: "44c021ab-be92-409b-99ad-4c3fe61d894a",
timestamp: "2017-07-01T12:00:00.000"
}, {
firstName: "Pete",
lastName: "Doe",
id: "017b4dab-d58b-475e-ab31-6363d9de25c0",
timestamp: "2017-07-01T13:30:00.000"
}, {
firstName: "Andy",
lastName: "NotRemote",
id: "2233e4cb-d324-463d-9a42-24b1b4cd3e11",
timestamp: null
}]
At the moment, I do not have access to libraries like underscore or lodash.
Thank you kindly for your assistance!