Radash
  1. Object
  2. keys

Basic usage

Given an object, return all of it’s keys and children’s keys deeply as a flat string list.

import { keys } from 'radash'

const ra = {
  name: 'ra',
  power: 100,
  friend: {
    name: 'loki',
    power: 80
  },
  enemies: [
    {
      name: 'hathor',
      power: 12
    }
  ]
}

keys(ra)
// => [
//   'name',
//   'power',
//   'friend.name',
//   'friend.power',
//   'enemies.0.name',
//   'enemies.0.power'
// ]

This is a function you might like to use with get, which dynamically looks up values in an object given a string path. Using the two together you could do something like flatten a deep object.

import { keys, get, objectify } from 'radash'

objectify(
  keys(ra),
  key => key,
  key => get(ra, key)
)
// => {
//   'name': 'ra'
//   'power': 100
//   'friend.name': 'loki'
//   'friend.power': 80
//   'enemies.0.name': 'hathor'
//   'enemies.0.power': 12
// }

As of v10.5.0+ you can get this behavior via the crush function