- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - assignInWith method
Syntax
_.assignInWith(object, sources, [customizer])
This method is like _.assignIn except that it accepts customizer which is invoked to produce the assigned values. If customizer returns undefined, assignment is handled by the method instead. The customizer is invoked with five arguments: (objValue, srcValue, key, object, source).
Arguments
object (Object) − The destination object.
sources (...Object) − The source objects.
[customizer] (Function) − The function to customize assigned values.
Output
(Object) − Returns object.
Example
var _ = require('lodash'); function customizer(objValue, srcValue) { return _.isUndefined(objValue) ? srcValue : objValue; } var defaults = _.partialRight(_.assignInWith, customizer); console.log(defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }));
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
{ a: 1, b: 2 }
lodash_object.htm
Advertisements
To Continue Learning Please Login
Login with Google