I've got an object and I want to update it with new data. But, if one of the keys has a value of undefined, I want it to have the same value it was priorly defined.
let obj
obj = {
name: 'Bill'
job: 'dev'
age: 22
}
const newObj = {
name: 'Sam',
age: 33
}
Object.keys(obj).forEach(key => {
obj[key] = newObj[key];
});
I want obj to return:
{
name: "Sam"
job:'dev',
age: 33,
}
But it returns:
{
age: 33,
job: undefined,
name: "Sam"
}
Also, it would help to return in the same order as the original.
if(key in newObj)before updatingundefined...