Description

JsonArray::remove() removes the element at the specified index from the array pointed by the JsonArray.

If the JsonArray is null, this function does nothing.

Signature

void remove(size_t index) const;

Arguments

index: the zero-based position of the element in the array.

Example

JsonArray array = doc.to<JsonArray>();
array.add("A");
array.add("B");
array.add("C");
array.remove(1);
serializeJson(array, Serial);

will print the following string to the serial output:

["A","C"]
Causes memory leaks ⚠️

Because JsonDocument contains a monotonic allocator, this function cannot release the memory associated with the removed element.

As a consequence, you cannot remove and add elements in a loop, otherwise the JsonDocument will overflow.

See also