get-by-field-name
v1.0.1
Published
This is my first repo I upload to npm
Downloads
3
Readme
get-by-field-name
Description
This is a very simple module that I have created for testing npm purpose.
This module exports only one function called getByFieldName
, that follows the currying function technical. It takes a field name as the only parameter and returns another function which takes an object and returns the value of the field name.
How to use
- Assume that you have an array of people like this:
const arr = [{ name: 'Tom', id: 1 }, {name: 'Alex', id: 2}]
- And you want to get list of names, so you can easily use
.map
built-in function of array withgetByFieldName
as below:const listNames = arr.map(getByFieldName('name'))