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

126
Views
Can't save the response into a dictionary

I have a function that is supposed to fetch from a recipes array that has a link of APIs to pull from.

for (let i = 0; i < recipes.length; i++) {
  console.log(recipes[i]);
  
  fetch(recipes[i]).then(response => {
    recipeData[recipes[i]] = response.json();
  }).catch(error => {
    console.log('Something went wrong fetching API');
  });
  console.log(recipeData[recipes[i]]);
}
console.log(recipeData.length)
if (recipeData.length == recipes.length) {
  resolve(true);
} else {
  reject('Could not fetch recipes');
}

I'm trying to save the response.json() into a dictionary, but it doesn't seem to be doing this because the recipeData dictionary is undefined. Why is this happening?

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!