Skip to main content

update

_.update(path, updater, object) # Ⓢ [Ⓣ][1] Ⓝ

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).




Since​

4.6.0

Arguments​

  1. path (Array|string): The path of the property to set.
  2. updater (Function): The function to produce the updated value.
  3. object (Object): The object to modify.

Returns​

(Object): Returns object.

Example​

var object = { 'a': [{ 'b': { 'c': 3 } }] };

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

_.update('x[0].y.z', function(n) { return n ? n + 1 : 0; }, object);
// => 0