1

I make a request to the server to get an array of objects:

var eq = new Scorocode.Query("equipment");
eq.find().then((found) => {
  let equipment = found.result;
  console.info(equipment);
});

The console shows that the object was successfully received:

Result in console

How can I get an array outside of this query to work with array further? I tried to access through the declaration of a global variable, but it did not help, I always get 'undefined'.

  • "How can I get an array outside of this query to work with array further?" Basically you can't. Keep it as a promise if you assume it won't change. `const equipment = eq.find().then(found => found.result)` and later `equipment.then(equipment => {... /* use equipment here */})` – Yury Tarabanko Mar 10 '19 at 18:18
  • @Yury, I'm understood, thank you. But the problem is that I need to render this array of objects into a component in React. Do I have to do it inside promise ? – Никита Арсеньев Mar 10 '19 at 18:41

0 Answers0