Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

327
Views
I have a question about Cloud Firestore V9 and using React Js. In one of my docs, there is a map. How do I access this map?

firebase screenshot

enter image description here

There's a function named getSomethingTEST that I'm using to get the data. Then I have a 'temporary' button onPress={getSomethingTest}, but probably its going to be a useEffect not a button. Later I was going to set my state var "dataFB" to the tempStore array. But my issue is... I don't know how... So I tried to console.log my results of tempStore. And I got this.. the results in console Which I believe is a nested object inside of an array. So I tried some basic things like tempStore[0].name but its of course undefined. Also I wasn't sure how to reference a key of an object that has a space in it. For this example it was "Asem Jawa".

    const firebaseApp = initializeApp({
    apiKey: "Hidden",
    authDomain: "Hidden",
    projectId: "Hidden",
  });

  const db = getFirestore();
  const col_p = collection(db, "WNA-Pasteur");
  const docRef = doc(db, "WNA-Pasteur", "branchData");


  const [dataFB, set_dataFB] = useState([]);

  async function getSomethingTEST() {
    const tempStore = [];
    const docSnap = await getDoc(docRef);
    tempStore.push(docSnap.data());
    console.log(tempStore);
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are fetching a single document and docSnap.data() is an object containing that document's data. You don't have to push it an array that way.

async function getSomethingTEST() {
  const docSnap = await getDoc(docRef);
  console.log(docSnap.data().name)  
}

This should log the name but in your case, you don't have a property name in your object so it'll be undefined.

I wasn't sure how to reference a key of an object that has a space in it.

You can use brackets notation:

console.log(docSnap.data()["Asem Jawa"] || "Field missing")
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!