Skip to content

Instantly share code, notes, and snippets.

@Dmitra
Created October 31, 2018 12:51
Show Gist options
  • Save Dmitra/6d40f7655daeaad04d354e745166c0c2 to your computer and use it in GitHub Desktop.
Save Dmitra/6d40f7655daeaad04d354e745166c0c2 to your computer and use it in GitHub Desktop.
Get dot-separated deep keys of the object
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