decrement
Learn how to 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.
Atomicity
If the value at the specified path is not a number, the operation fails and the entire patch is discarded.
Signature
This method has the following signature:
patch.decrement(path: string, value: number = 1): PatchThe 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 value | Amount | Result |
|---|---|---|
| null | 10 | -10 |
| 0 | 10 | -10 |
| 1 | 10 | 9 |
Parameters
The following list describes the supported parameters: