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

177
Views
Recorra una matriz y llame a una API para cada 2 elementos por cada 10 segundos y obtenga datos - JS

Estoy recorriendo una matriz y llamando a un punto final para obtener datos por elemento. Quiero llamar a cada 2 elementos juntos, luego esperar 10 segundos y llamar a los siguientes dos elementos y así sucesivamente hasta que la lista esté completa. Probé una solución pero no funciona. Por favor, ayúdame en lo que estoy haciendo mal.

Aquí está el código.

 const data = [{ name: '1', id: 1, }, { name: '2', id: 2, }, { name: '3', id: 3, }, { name: '4', id: 4, }, { name: '5', id: 5, }, { name: '6', id: 6, }] const result = data.reduce(async(a, c, i) => { let counter = 0; if (counter > 2) { setTimeout(() => { counter = 0; }, 10000) } const res = await a; res.push({ name: c.name, id: c.id, title: (await (await fetch(`https://jsonplaceholder.typicode.com/posts/${c.id}`)).json()).title }) await counter++; return res }, Promise.resolve([])) result.then(a => console.log(a))

about 4 years ago · Juan Pablo Isaza
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!