Got two objects:
master = [ { "id": 411, "state": 1 },
{ "id": 2134, "state": 1 },
{ "id": 2135, "state": 0 },
{ "id": 2137, "state": 0 } ]
zips = [ { "id": 411, "zip": "90201" },
{ "id": 412, "zip": "90201" },
{ "id": 2134, "zip": "90201" },
{ "id": 2137, "zip": "90201" } ]
I'd like to merge them together only if the id in zips exists in devices. Using the above data, the result should be:
master = [ { "id": 411, "state": 1, "zip": "90201" },
{ "id": 2134, "state": 1, "zip": "90201" },
{ "id": 2135, "state": 0 },
{ "id": 2137, "state": 0, "zip": "90201" } ]
id: 412 is zips is 'skipped' because it's not in the devices object.
I've looked at looping through functions like Object.assign or merging with ... , but they have undesirable results (like adding the id 412 above because it exists in the second object)
Any hints or tips or better places to look are greatly appreciated!