Object.filter

Object.filter

Object.filter

Function

Filters the key-value pairs for which the callback result is true and returns a new object.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
callbackFnNoEmptyThe callback signature is fn(value, key, current).

Return value

TypeDescription
ObjectReturns the new object after filtering.

Return object fields

The returned object only contains the fields in the original object that make the callback result true. The field name remains unchanged, and the field value remains the original value; the field that fails the filter does not exist, and the reading result is empty.

Example

Notes

  • filter does not modify the original object.
  • The callback traverses the object snapshot at the beginning of the call.