Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 860 Bytes

filter.md

File metadata and controls

36 lines (24 loc) · 860 Bytes

objects.filter

filter(object, predicate)

Filter iterates over an object and applies a predicate to each property, for all properties where the predicate is true, return that property in a new object. Function is invoked with 3 arguments (value, key, object)

Arguments

  1. object (Object): input object
  2. predicate (Function): predicate function to check what properties to include

Returns

(Object): object with selected properties

Example

const obj = { small: "ant", medium: "dog", big: "elephant" }
const result = objects.filter(obj, (value, key, object) => ['small', 'big'].includes(key)));
console.log(result);
> { small: "ant", big: "elephant" }