Created
April 13, 2017 13:55
-
-
Save dlebedynskyi/d6828f9cb4882636077e8eb8fff6c0d5 to your computer and use it in GitHub Desktop.
get deep nested object prop. functional way.
This file contains 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
// https://medium.com/javascript-inside/safely-accessing-deeply-nested-values-in-javascript-99bf72a0855a | |
const idx = p => o => | |
p.reduce((xs, x) => | |
(xs && xs[x]) ? xs[x] : null, o) | |
const getUserComments = idx(['posts', 0, 'comments']) | |
const user = {} | |
console.log(getUserComments(user)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment