const obj1 = { a: 1, b: 2 };
const obj2 = { c: 3, d: 4 };
const result = mergeObjects(obj1, obj2);
console.log(result); // { a: 1, b: 2, c: 3, d: 4 }
const obj1 = { a: 1, b: [1, 2] };
const obj2 = { b: [3, 4], c: 4 };
const result = mergeObjects(obj1, obj2);
console.log(result); // { a: 1, b: [1, 2, 3, 4], c: 4 }
const obj1 = { a: { b: 1, c: [1, 2] } };
const obj2 = { a: { c: [3, 4], d: 4 }, e: 5 };
const result = mergeObjects(obj1, obj2);
console.log(result); // { a: { b: 1, c: [1, 2, 3, 4], d: 4 }, e: 5 }
Generated using TypeDoc
Uses deep merge way to merge objects. Source will be merged with target.