user2828442
user2828442

Reputation: 2515

Fetch value of array object using get() in Firestore

I am getting value of doc.data() using get().

Console.log(doc.data()) reads:

{ 'abc': 
   [ { fullname: 'samar chadha',
       number: 1,
       authid: '8SlzKpqVdXWGQ4dk7zVP23Uh0Pr2' } ] } 

I need to fetch the value of number in a variable.

When I try like this doc.data().abc[0].number it gives error.

How do I fetch this value in a variable ?

This is how it looks in console [here abc is 9-JUN-2020]

enter image description here

Upvotes: 0

Views: 32

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83068

The following should do the trick:

const abc = "9-JUN-2020";
const numberVar = doc.data()[abc][0].number;

It uses the square brackets notation

Upvotes: 1

Related Questions