clear
Clear the value at the given path.
This method chains an clear operation to the patch, which empties values without deleting the path.
For collections, it removes all elements, for all other types, it sets null.
The difference between unset and clear is that unset deletes the path, while clear removes the value by setting it to null or removing all of its elements.
This operation does not fail if the path does not exist.
Signature
This method has the following signature:
patch.clear(path: string): 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.clear('interests');
The following table shows how the operation behaves in different scenarios:
Current value | Result |
---|---|
null | null |
[] | [] |
['a'] | [] |
'foo' | null |
Parameters
The following list describes the supported parameters:
- pathstring
The path to the value to clear in dot notation, like interests.