Deep merge two objects, combining nested properties.
Code
Generalconst deepMerge = (t, s) => {
const result = { ...t };
for (const key of Object.keys(s)) {
result[key] = (t[key] && typeof t[key] === 'object' && typeof s[key] === 'object')
? deepMerge(t[key], s[key]) : s[key];
}
return result;
};
return deepMerge(target, source);Parameters
Target object
Source object
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Count Object Properties
Count the number of enumerable properties in an object.
Deep Clone Object
Create a deep copy of an object (handles nested objects and arrays).
Deep Equal
Check if two values are deeply equal by recursively comparing all nested properties. Works with objects, arrays, and primitives.
Deep Freeze Object
Recursively freeze an object and all nested objects to make them immutable.
Flatten Object
Flatten a nested object to a single level with dot notation keys.
Get Nested Value
Safely get a nested property value from an object.