let people = [ { firstName: 'Ben' }, {firstName : 'Bob' } ];
let location = { city: 'Dublin' , Country: 'Ireland' } ;
let result = [];
let tempObj = {};
for(let person of people){
tempObj = Object.assign({}, location);
tempObj['fname'] = person.firstName;
result.push(tempObj);
}
expected output :
[ {fname:'Ben', city: 'Dublin' , Country: 'Ireland'}, {fname:'Bob',city:
'Dublin' , Country: 'Ireland'}]
what I'm getting is:
[ {fname:'Ben', city: 'Dublin' , Country: 'Ireland'}, {fname:'Ben', city: 'Dublin' , Country: 'Ireland'}}]
What am I doing wrong here?