Created
June 4, 2018 08:46
-
-
Save chomamateusz/f48f8d917ac8eabfd12cad68edabfbd0 to your computer and use it in GitHub Desktop.
mapObjectToArray
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
// 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