I am trying to figure out how to take an array of two objects and merge them into a single object.
First off, here's what I did to produce my combined array from two arrays:
let p;
let v;
let combinedArray = [];
for (let diff of differences) {
for (let mapping of mappings) {
if (diff.path[0] === mapping.rhs) {
p = diff.path[0];
v = diff.rhs;
combinedArray.push({ p, v });
}
}
}
The resulting combined array looks like this:
[ { p: 'prop_1', v: 'x1' },
{ p: 'prop_2', v: 'x2' } ]
What I need to do next is create a final object that looks like this:
{ 'prop_1': 'x1', 'prop_2': 'x2' }
How can I do that from the results of my "combined" array above? And, by the way, if there's a simpler way to do this from the outset of my initial two arrays I'm all for it. Open to suggestions here.