Lodash - update method



Syntax

_.update(object, path, updater)

This method is like _.set except that accepts updater to produce the value to set. Use _.updateWith to customize path creation. The updater is invoked with one argument: (value).

Arguments

  • object (Object) − The object to modify.

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

  • updater (Function) − The second number in an addition.

Output

  • (Object) − Returns object.

Example

var _ = require('lodash');
var object = { 'a': [{ 'b': { 'c': 3 } }] };

_.update(object, 'a[0].b.c', function(n) { return n * n; });

console.log(object.a[0].b.c);

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

Command

\>node tester.js

Output

9
lodash_object.htm
Advertisements