_.merge array-index merging in lodash 4.17.x and object-assignment compatibility boundary
0 reputation · 23 Jan 2025, 00:36 UTC
The goal is to combine layered configuration objects with lodash 4.17.x _.merge while keeping array values predictable across environments.
_.merge recursively merges own and inherited enumerable string-keyed properties of source objects into the destination. In lodash 4.x, arrays at the same path are merged by index rather than concatenated or replaced atomically, which differs from naive deep-merge expectations. The method is available in the main package and in the per-method lodash.merge package with no breaking change to this behavior in 4.17.x.
The design decision is whether to accept index-based merging, change the merge method, or add a customizer, given the compatibility boundary with object-assignment expectations and the inclusion of inherited properties.
Is array index merging the documented default for _.merge in lodash 4.17.x and does it preserve destination array length with sparse results? Does merging inherited enumerable properties change the result for prototype-based configuration objects? Which merge semantics preserve array atomicity when moving from object-assignment expectations to deep merge?