Skip to content

Instantly share code, notes, and snippets.

@rtmalone
Last active July 13, 2017 15:26
Show Gist options
  • Select an option

  • Save rtmalone/48789c81c866ef5d41e1cf19a46c72fc to your computer and use it in GitHub Desktop.

Select an option

Save rtmalone/48789c81c866ef5d41e1cf19a46c72fc to your computer and use it in GitHub Desktop.
Turn Firebase snapshot into Array
// 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