0

Im kinda new in firebase. As a first step, I would like to set a post and get calls to my newly made database in firebase.

Firebase has a lot of native functions which allows me to get elements and push them to the db. However, I would prefer to use native get/post calls.

My post calls seem to work just fine, it properly stores an element in the db and returns 200 status.

When I enter to my DB in firebase, I can see that it posses following data:

entries:
  -L1cxn3-rLgp7PsPwjV3
     author: "Mark"
     title: "Hello"
  -L1cyaOQ4TUYd3m16VfT
     autor: "Lily"
     title: "Hi"

So as I said before, it stores correct data. But the structure is unknown for me. It's like a map or an object.

I would like to ask you for help, how to properly retrieve it from get call.

The get call returns:

{"-L1cxn3-rLgp7PsPwjV3":{"author":"Mark","title":"Hello"},"-L1cyaOQ4TUYd3m16VfT":{"author":"Lily","title":"Hi"}};

I could take all keys from it Object.keys(data)

Then iterate over it to get it as an array - Object.keys(data).map(r => data[r])

Now I would have an array of objects.

Is it a proper way to deal with it? Should I stay with my get/post calls or I should rather use firebase built-in functions? Thank u in advance! :)

1 Answer 1

1

Just use Object.values() if you want the array of objects

console.log(Object.values({"-L1cxn3-rLgp7PsPwjV3":{"author":"Mark","title":"Hello"},"-L1cyaOQ4TUYd3m16VfT":{"author":"Lily","title":"Hi"}}))

Sign up to request clarification or add additional context in comments.

1 Comment

Object.entries() would be a better approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.