Skip to content

Instantly share code, notes, and snippets.

@kindaro
Created March 20, 2016 09:57
Show Gist options
  • Save kindaro/6b164977acda2211914d to your computer and use it in GitHub Desktop.
Save kindaro/6b164977acda2211914d to your computer and use it in GitHub Desktop.
Object.deep_extract (obj, props)
Object.deep_extract =
(obj, props) ->
if props.length == 0
obj
else
prop = props[0]
if obj[prop]? then Object.deep_extract obj[prop], props[1..] else undefined
test_object =
1:
'key': 'value'
2: 'b'
3: 'c'
console.log Object.deep_extract test_object , ['1', 'key']
console.log Object.deep_extract test_object , ['some', 'other', 'key']
# Output:
# > value
# > undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment