简体   繁体   中英

React Native Firestore - Get field values

I want to save my field values into a local array.
Example:
图片
I will get ["84724302","60855802"] And by the way the field name is not 0 & 1 .

When I'm trying to do it with documentSnapshot.data() it returns this result: [{"field_name": "84724302", "field_name": "60855802"}]
But I need to get this result: ["84724302","60855802"]

just convert the object that you are getting to an array

firestore.collection('collection').doc('123').onSnapshot(doc=>{
  const arr=Object.values(doc.data())
 console.log(arr) // ["84724302","60855802"]
//...
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM