filter-map
Returns a copy of a Map or Object containing only those entries which pass a test function.
Supports a numeric limit on the number of entries in the resulting Map or Object.
Installation
npm install filter-map --save
Usage
const filterMap = const map = 'a' 1 'b' 2 'c' 3const filteredMap = filteredMapsize // 2 // Works on objects tooconst obj = a: 1 b: 2 c: 3 // {b: 2, c: 3}
If no test function is provided, values are filtered by truthiness:
const filterMap = const map = 1 true 2 false 3 truesize // 2 // {1: true, 3: true}
If you only want a certain number of entries in the filtered Map or Object, you can specify a numeric limit parameter:
const obj = a: 0 b: 1 c: 2 d: 3 // {c: 2} // {b: 1}