I am using a for loop to iterate over two arrays and generate an object. That's working, but I need the final object in a slightly different format.
First off, here's the code that iterates over the arrays and forms my object:
differences:
[ { kind: 'N', path: ['id_number'], rhs: '1' },
{ kind: 'N', path: ['person_firstname'], rhs: 'x1' },
{ kind: 'N', path: ['person_lastname'], rhs: 'x2' } ]
mappings: [ { lhs: 'name.first', rhs: 'person_firstname' },
{ lhs: 'name.last', rhs: 'person_lastname' },
{ lhs: 'name.middle', rhs: 'person_middlename' } ]
let outResult = {};
for (let diff of differences) {
for (let mapping of mappings) {
if (diff.path[0] === mapping.rhs) {
p = mapping.lhs;
v = diff.rhs;
outResult[p] = v;
}
}
}
What this gives me is an object that looks like this:
{ name.first: 'x1', name.last: 'x2' }
The format I need to fit my model should be this:
name: {
first: "x1",
last: "x2"
}
};
What operation(s) can I use here to format this in the way I need?