-2

I have a function in my React App that gets data form an Api takes in an array of objects. Loops through that array makes a dynamic call to that api then pushes the result onto dailyPredictions array and returns that array.

When I console daily predictions to the console I see this : Chrome console.log of dailyPredictions

I can't use any methods for example .length, .forEach, .slice.

What am I doing wrong?

export const getPredictions = data => {
  return new Promise((resolve, reject) => {
    let dailyPredictions = [];

    data.forEach(fixture => {
      axios
        .get(`${predictionsEndPoint}/${fixture.fixture_id}`)
        .then((fixturePredictions)=> {
          console.log(fixturePredictions);
          fixturePredictions.data.api.predictions[0].fixture_id =
            fixture.fixture_id;
          dailyPredictions.push(fixturePredictions.data.api.predictions[0]);
        })
        .catch(err => {
          console.log(err);
          reject(err);
        });
    });
    resolve(dailyPredictions);
  });
};

0 Answers