2

I am trying to access the dictionary in the "workload" in my document in firestore, however I am having difficulties trying to do so. This is my code:

async addTask() {
    const projectDoc = await getDoc(doc(db, "projects", "TestingNewNew"))
    const projectData = projectDoc.data();
    const employeeWorkload = projectData.workload
    console.log(employeeWorkload)
    console.log(employeeWorkload["Jimmy"])
}

When I console.log() the entire dictionary, I get the correct output, however when I try to access the dictionary through a particular, my console.log() reads undefined.

console

This is how my document in firestore looks

Firestore document

I tried many differents ways. I tried using the JSON.parse(JSON.stringify()) method, but it still doesn't work. Please advice me on how I can approach the problem. Thank you.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Elson
  • 21
  • 1

1 Answers1

0

Google APIs often make use of computed getters on objects and classes. These getters can lose their context (this) when reassigned to different variables.

This is what you're doing here:

const employeeWorkload = projectData.workload

You should be able to see the correct output if you do this:

console.log(projectData.workload.Jimmy)
Viktor Luft
  • 857
  • 3
  • 8