Last active
June 23, 2017 06:52
-
-
Save chriswrightdesign/20c318a047ddbc3a0ae4c46e91cc86e1 to your computer and use it in GitHub Desktop.
Example list of objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getValue = property => obj => obj && obj[property]; | |
// Example List of users | |
const users = [{ | |
name: 'sarah', | |
id: '12345', | |
country: 'Australia', | |
}, | |
{ | |
name: 'bob', | |
id: '34325', | |
country: 'New Zealand', | |
}, | |
{ | |
name: 'Sam', | |
id: '42524', | |
country: 'Australia', | |
}, | |
{ | |
name: 'Roger', | |
country: 'USA', | |
id: '314135' | |
}]; | |
users.map(getValue('id')); | |
// result: ['12345', '34325', '42524', '314135'] | |
/** | |
Every array value is being passed a function - the result of getValue('id') | |
which looks like this (obj) => obj && obj[property]; | |
it has retained value ('id') from the outter call | |
which then returns '12345', '34325', '42524', '314135' | |
**/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment