increment

Increment a value by a given amount.

This method chains an increment operation to the patch, which increments a numeric value by a given amount.

Non-existent paths and null values are treated as zero.

Signature

This method has the following signature:

patch.increment(path: string, value: number = 1): Patch

The return is the Patch instance itself to allow operation chaining.

Example

Here is a basic example of how to use this method:

patch.increment('score', 10);

The following table shows how the operation behaves in different scenarios:

Current valueAmountResult
null1010
01010
-1109

Parameters

The following list describes the supported parameters:

path
string

The path to the value to increment in dot notation, like points.

value(optional)
number

The amount to increment the value by, like 2.

Default:1