I am looking for a way to blend two simple, flat JavaScript objects dynamically during runtime. For instance, suppose I have one object representing meal details and another containing pet information. I’d like to merge the properties so that one object holds all the key-value pairs without involving recursion or merging of functions. Below is an example of an alternative approach:
let details1 = { dish: 'sushi', vehicle: 'tesla' };
let details2 = { pet: 'cat' };
function combineAttributes(target, source) {
Object.keys(source).forEach(function(key) {
target[key] = source[key];
});
return target;
}
combineAttributes(details1, details2);
// Now 'details1' contains dish, vehicle, and pet properties
Is there a native function available to perform this merge?