Skip to content

Instantly share code, notes, and snippets.

@chomamateusz
Created June 4, 2018 08:46
Show Gist options
  • Save chomamateusz/f48f8d917ac8eabfd12cad68edabfbd0 to your computer and use it in GitHub Desktop.
Save chomamateusz/f48f8d917ac8eabfd12cad68edabfbd0 to your computer and use it in GitHub Desktop.
mapObjectToArray
// this function maps an object into array of objects
// and puts object keys into key property of array items
const mapObjectToArray = (obj) => (
Object.entries(obj || {})
.map(([key, value]) => (
typeof value === 'object' ?
{...value, key}
:
{key, value}
))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment