Created
October 31, 2018 12:51
-
-
Save Dmitra/6d40f7655daeaad04d354e745166c0c2 to your computer and use it in GitHub Desktop.
Get dot-separated deep keys of the object
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
import _ from 'lodash' | |
const o = { | |
a: 1, | |
b: { | |
c: 2 | |
} | |
} | |
const getKeysDeep = o => ( | |
_(o).map((v, k) => { | |
if (_.isPlainObject(v)) return _.map(getKeysDeep(v), subK => `${k}.${subK}`) | |
return k | |
}).flatten().value() | |
) | |
const keys = getKeysDeep(o) // => ['a', 'b.c'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment