remove

Remove values from a collection.

This method chains a remove operation to the patch, which removes one or more values from a collection.

If the path does not exist or the target values are not present, the operation succeeds without any effect.

Signature

This method has the following signature:

patch.remove(path: string, value: JsonValue): Patch

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

Example

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

path.remove('interests', 'data science');

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

Current valueGiven valueResult
['a', 'b', 'c']'a'['b', 'c']
['a', 'b', 'c', 'c']'c'['a', 'b']
['a', 'b', 'c']'d'['a', 'b', 'c']
['a', {b: 1}, 'c']{b: 1}['a', 'c']

Parameters

The following list describes the supported parameters:

path
string

The path to the collection in dot notation, like interests.

value
JSON

The element to remove from the collection, like data science.