decrement

Decrement a value by a given amount.

This method chains an decrement operation to the patch, which decrements 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.decrement(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.decrement('score', 10);

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

Current valueAmountResult
null10-10
010-10
1109

Parameters

The following list describes the supported parameters:

path
string

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

value(optional)
number

The amount to decrement the value by, like 2.

Default:1