add after ary assign assignIn assignInWith assignWith at before bind bindAll bindKey camelCase capitalize castArray ceil chain chunk clamp clone cloneDeep cloneDeepWith cloneWith compact concat conformsTo countBy create curry curryRight debounce deburr defaults defaultsDeep defer delay difference divide drop dropRight each eachRight endsWith entries entriesIn eq escape every extend extendWith fill filter find findIndex findKey findLast findLastIndex findLastKey first flatMap flatMapDeep flatMapDepth flatten flattenDeep flattenDepth flip floor forEach forEachRight forIn forInRight forOwn forOwnRight fromPairs functions functionsIn get groupBy gt gte has hasIn head inRange includes indexOf initial intersection invert invertBy invoke invokeMap isArguments isArray isArrayBuffer isArrayLike isArrayLikeObject isBoolean isBuffer isDate isElement isEmpty isEqual isEqualWith isError isFinite isFunction isInteger isLength isMap isMatch isMatchWith isNaN isNative isNil isNull isNumber isObject isObjectLike isPlainObject isRegExp isSafeInteger isSet isString isSymbol isTypedArray isUndefined isWeakMap isWeakSet join kebabCase keyBy keys keysIn last lastIndexOf lowerCase lowerFirst lt lte map mapKeys mapValues max maxBy mean meanBy memoize merge mergeWith min minBy multiply negate nth omit omitBy once orderBy overArgs pad padEnd padStart parseInt partial partialRight partition pick pickBy pull pullAll pullAllBy pullAllWith pullAt random rearg reduce reduceRight reject remove repeat replace rest result reverse round sample sampleSize set setWith shuffle size slice snakeCase some sortBy sortedIndex sortedIndexOf sortedLastIndex sortedLastIndexOf sortedUniq split spread startCase startsWith subtract sum sumBy tail take takeRight tap template throttle thru toArray toFinite toInteger toLength toLower toNumber toPairs toPairsIn toPlainObject toSafeInteger toString toUpper transform trim trimEnd trimStart truncate unary unescape union uniq uniqBy uniqWith unset unzip unzipWith update updateWith upperCase upperFirst values valuesIn without words wrap wrapperAt wrapperChain wrapperCommit wrapperFlatMap wrapperLodash wrapperNext wrapperPlant wrapperReverse wrapperToIterator wrapperValue xor zip zipObject zipObjectDeep zipWith

Lodash _.merge


The lodash library provides a utility method called _.merge which is used to deeply merge two or more plain object arguments. The method combines the properties of the source object(s) into the destination object recursively. If the same property exists in both the source and destination objects, then the value from the source object overrides the value in the destination object.

The syntax of the _.merge method is as follows:

_.merge(object, [sources])

where object is the destination object and sources are the source object(s) to merge into the destination object.

The _.merge method returns the modified destination object.

The _.merge method can be used to merge properties of multiple objects into a single object. This method is particularly useful when dealing with configuration options or merging different data sources.

Here is an example of using the _.merge method:

const object1 = {
  a: [{ b: 2 }, { d: 4 }]
const object2 = {
  a: [{ c: 3 }, { e: 5 }]
_.merge(object1, object2);
// Output: { a: [{ b: 2, c: 3 }, { d: 4, e: 5 }] }

In the above example, we have two objects object1 and object2. Both objects have the same property a which is an array of objects. When we pass these objects to the _.merge method, it combines the properties of the a arrays into a single array. The resulting object has only one property a which contains the merged array.

It is important to note that _.merge only merges plain objects. It does not merge functions or non-enumerable properties.

In conclusion, the _.merge method is a powerful utility method in the lodash library that can be used to deeply merge two or more objects. It is a useful tool for merging configuration options or data from multiple sources.