1.0.7 • Published 3 years ago
filter-and-map v1.0.7
filter-and-map
Installation
npm install filter-and-mapUsage
In your code's entry point (usually index.* or main.*), include the following line:
import 'filter-and-map';You should now have access to Array.prototype.filterAndMap throughout the entirety of your code.
Array.prototype.filterAndMap
The Array.prototype.filterAndMap method can be used like so:
const example = [
{ id: 1, isValid: true, name: "Bret" },
{ id: 2, isValid: false, name: "Gary" },
{ id: 3, isValid: true, name: "Shafran" }
]
const result = example.filterAndMap((item) => {
if (item.isValid) return item.name;
});
// or we could write:
const result = example.filterAndMap((item) => item.isValid ? item.name : undefined);