What this thread does
Do first: pass a fresh destination to _.assign or _.merge, then decide whether nested objects and arrays should replace whole sections or combine recursively.
Short answer
As of November 2026, the release listing identifies Lodash 4.18.1. _.assign copies own enumerable string keyed source properties to the destination (assign source); _.merge recursively merges own and inherited enumerable string keyed properties (merge reference).
Choose / don't choose
_.assign: choose when a later configuration section replaces an earlier section entirely._.merge: choose when missing nested fields should retain defaults.- Customizer return: choose when nested objects merge but source arrays replace; don't return
undefinedfor an array you intend to replace, because merging is then handled by the method (customizer contract).
Not for: reducing a JavaScript dependency bundle; see vite-react-bundle-too-large-find-and-cut-production-javascript.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| Source properties | Use {} as fresh destination; own enumerable string keyed source properties are assigned to the destination | 4.18.1 | assign source |
_.merge(object, sources) | Use {} as destination for ordinary configuration data; plain objects and arrays combine recursively; later sources win at visited properties | 4.18.1 | docs, array handling |
customizer | For an array srcValue, return _.cloneDeep(srcValue); if customizer returns undefined, merging is handled by the method | 4.18.1; application array-replacement policy | customizer API, clone API |
_.cloneDeep(value) | Recursively clone configuration sections that must not share nested references | Current Lodash API | docs |
_.assignIn | Iterates over own and inherited source properties; prefer _.assign when only own properties belong in the configuration | Current Lodash API | docs |
Order of operations
1. Define source precedence: defaults first, overrides later. Pass a new destination, not the defaults object. 2. Select whole-section replacement with assign or recursive combination with merge. The source describes recursive merging of objects and arrays in the array implementation. 3. For replacement arrays with recursively merged objects, apply this application customizer derived from the API contract:
function customizer(objValue, srcValue) {
if (_.isArray(srcValue)) return _.cloneDeep(srcValue);
}
Pass that function last to _.mergeWith. The API delegates to normal merging when a customizer returns undefined. Cloning prevents later edits to the replacement array or its elements from mutating the source (clone contract).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
merge should not ignore empty array | The report's empty source array leaves existing elements | Use an array-replacement customizer, including for empty arrays | vincentcr, July 2, 2015, merge implementation |
Missing
- No exception is thrown for choosing the wrong merge policy; these are data-shape and aliasing failures.
- Merge is not a universal deep clone: non-plain values, custom objects and application-specific semantics need their own policy.
Checked
2026-11-12; Lodash 4.18.1 registry/release entries, assign/merge/mergeWith/clone documentation, tagged assign/merge/customizer source, and vincentcr's dated report read. No merge example executed.
Started from a post by @Lodash, packaged by the editor. Original post