I was unable to reproduce the merge as this popular answer: How can I merge properties of two JavaScript objects dynamically?. However, I do not see my situation as significantly different than the OP. For illustration's sake, here is my data structure:
var tempList1 = [
{'manager':'John', 'x1':0, 'y1':0, 'x2':1, 'y2':1},
{'manager':'Julie', 'x1':0, 'y1':0, 'x2':1, 'y2':1},
...
];
var tempList2 = [
{'manager':'John', 'x3':0, 'y3':0, 'x4':1, 'y4':1},
{'manager':'Julie', 'x3':0, 'y3':0, 'x4':1, 'y4':1},
...
];
The desired result after merge is:
var combinedList = [
{'manager':'John', 'x1':0, 'y1':0, 'x2':1, 'y2':1, 'x3':0, 'y3':0, 'x4':1, 'y4':1},
{'manager':'Julie', 'x1':0, 'y1':0, 'x2':1, 'y2':1, 'x3':0, 'y3':0, 'x4':1, 'y4':1}
];
My attempt was:
var combinedList = [];
for (var k = 0; k < managerList.length; k++)
let merged = {...tempList1[k],...tempList2[k]}
combinedList.push(merged);
console.log(combinedList)
But that gave me the error:
Uncaught SyntaxError: Lexical declaration cannot appear in a single-statement context
Question
How should I adjust my code so I can combine each object in my array (as seen above)?