0

I am currently dealing with an API request that returns an array of project statistics in JSON format. I am sending a GET request to the API using the Axios library and then attempting to store the returned result inside of a variable like so:

  let userProjects = api.getAllProjects().then((res) => {

    return res.data;

  }).catch((err) => {

    console.log(err);
    return err;

  });

However, in the above code snippet, after executing the program, userProjects is equal to Promise {<pending>} with three sub-categories - [[Prototype]]: Promise, [[PromiseState]]: "fulfilled", [[PromiseResult]]: Array(6). I want userProjects to equal the [[PromiseResult]] data and nothing else, yet I am struggling to figure out how to do this. I am relatively new to JS and its asynchronous nature meaning I cannot make sense of the current answers to similar questions. Any suggestions on how to make userProjects equal the promise result would be greatly appreciated. Thanks in advance.

pythonoob
  • 35
  • 4

0 Answers0