Lodash - updateWith method


Advertisements

Syntax

_.updateWith(object, path, updater, [customizer])

This method is like _.update except that it accepts customizer which is invoked to produce the objects of path. If customizer returns undefined path creation is handled by the method instead. The customizer is invoked with three arguments: (nsValue, key, nsObject).

Arguments

  • object (Object) − The object to modify.

  • path (Array|string) − The path of the property to set.

  • updater (Function) − The function to produce the updated value.

  • [customizer] (Function) − The function to customize assigned values.

Output

  • (Object) − Returns object.

Example

var _ = require('lodash');
var object = {};
 
_.updateWith(object, '[0][1]', _.constant('a'), Object);

console.log(object);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

{ '0': { '1': 'a' } }
lodash_object.htm
Advertisements