Skip to content

Instantly share code, notes, and snippets.

@thadeu
Last active June 26, 2019 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thadeu/10f90da53a3a6b387843c718a53d4791 to your computer and use it in GitHub Desktop.
Save thadeu/10f90da53a3a6b387843c718a53d4791 to your computer and use it in GitHub Desktop.
Nested Pick Object

Patch

export function pick(o, ...keys) {
  return keys.reduce((acc, k) => (Boolean(acc[k]) ? acc[k] : ''), o)
}

Example Use

const items = {
  a: {
    b: {
      c: {
        total: 100
      }
    }
  }
}

pick(items, 'a', 'b', 'c', 'total')
// 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment