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

104
Views
¿Cómo manejar una Promesa en una matriz?

Tengo problemas para ir más allá con mi Promesa que se devuelve desde getPostedPlaces() . Cuando ejecuto getAll() , imprime la matriz que se ve a continuación. La matriz parece correcta, pero ¿cómo obtengo la función getAll() para devolver una matriz real? Solo puedo imprimirlo, pero no puedo devolver la matriz en sí. También intenté empujar el objeto dentro de la matriz a una matriz, pero vuelve vacío. Frustrante.

 const getPostedPlaces = async () => { const querySnapshot = await getDocs(collection(db, "posted_places")); const newSnapshot = querySnapshot.docs.map(doc => { let newDoc = doc.data(); newDoc.id = doc.id; return newDoc; }); return newSnapshot; } const getAll = () => { getPostedPlaces().then(res => console.log(res)) }

La matriz:

 Array [ Object { "active": true, "category": Array [ "tøj", "møbler", ], "email": "bar@gmail.com", "house_nr": 1, "id": "i3juWf6Rj4OPBoKAjkBD", "location": Object { "latitude": 55.69718057, "longitude": 12.52470763, }, "price_interval": Array [ 100, 700, ], "street_name": "Hvidkildevej", "time_end_actual": "", "time_end_expected": "Sat Feb 05 2022 18:00:00 GMT+0100 (CET)", "time_start": "Sat Feb 05 2022 09:00:00 GMT+0100 (CET)", "zip_code": 2400, }, ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe agregar una devolución ya que está usando {}

 const getAll = async () => { // since you use {} you need to use return below return getPostedPlaces().then(res => { console.log(res) return res; //you need to return res here. }) }

Luego, cuando usas getAll, tiene que ser

 await getAll()

Ejemplo donde no se necesita return , es cuando no usa {}

 const getAll = async() => getPostedPlaces()
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!