combine
Learn how to combine two sets of values.
This method chains a combine operation to the patch, which combines two sets of values without duplicates.
Non-existent paths and null values are treated as an empty collection.
Atomicity
If the value at the specified path is not a collection, the operation fails and the entire patch is discarded.
Signature
This method has the following signature:
patch.combine(path: string, value: JsonValue): PatchThe return is the Patch instance itself to allow operation chaining.
Example
Here is a basic example of how to use this method:
path.combine('interests', 'data science');The following table shows how the operation behaves in different scenarios:
| Current value | Given value | Result |
|---|---|---|
| [] | [] | [] |
| [] | ['a', 'a'] | ['a'] |
| ['a'] | null | ['a'] |
| ['a'] | 'b' | ['a', 'b'] |
| ['a'] | ['b', null] | ['a', 'b'] |
| [null] | ['a'] | ['a'] |
| null | null | [] |
| null | ['a'] | ['a'] |
| null | 'a' | ['a'] |
| 'a' | 'b' | ['a', 'b'] |
| 'a' | ['b'] | ['a', 'b'] |
| 'a' | ['a'] | ['a'] |
Parameters
The following list describes the supported parameters: