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

133
Views
No capturado (en promesa) TypeError: photos.forEach no es una función - Analizando la API de fotos unsplash

¿Me perdí algo? Todavía recibo este registro: Uncaught (en promesa) TypeError: photos.forEach no es una función. No tengo idea de lo que estoy haciendo mal.

 async fetchImages(baseURL){ const response = await fetch(baseURL, { method: 'GET', headers:{ Accept: 'application/json', Authorization: this.API_KEY } }); const photos = await response.json(); return photos; } GenerateHTML(photos){ photos.forEach(photo => { const item = document.createElement('div'); item.classList.add('item'); item.innerHTML = ` <a href='#'> <img src="${photo.urls.small}"> <h3>${photo.user.name}</h3> </a> `; this.galleryDiv.appendChild(item); }); } async getSearchedImages(e){ e.preventDefault(); const searchValue = e.target.querySelector('input').value; const baseURL = await `https://api.unsplash.com/search/photos?page=1&query=${searchValue}&client_id=${this.API_KEY}` const photos = await this.fetchImages(baseURL); this.GenerateHTML(photos); }

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Según la documentación , la respuesta se sirve como

 { "total": 133, "total_pages": 7, "results": [ //Photos here ] }

Entonces deberías cambiar la función GenerateHTML

 GenerateHTML(photos){ photos.results.forEach(photo => { const item = document.createElement('div'); item.classList.add('item'); item.innerHTML = ` <a href='#'> <img src="${photo.urls.small}"> <h3>${photo.user.name}</h3> </a> `; this.galleryDiv.appendChild(item); }); }
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!