Last active
July 13, 2017 15:26
-
-
Save rtmalone/48789c81c866ef5d41e1cf19a46c72fc to your computer and use it in GitHub Desktop.
Turn Firebase snapshot into Array
This file contains hidden or 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
| // as if in a utils.js file | |
| const isObject = obj => { | |
| return Object.prototype.toString.call(obj) === '[object Object]' | |
| ? true | |
| : false; | |
| }; | |
| export const toArray = snap => { | |
| const array = []; | |
| snap.forEach(child => { | |
| const val = child.val(); | |
| if (isObject(val)) { | |
| val.key = child.key; | |
| } | |
| array.push(val); | |
| }); | |
| return array; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment