0

I have a function loadData which attemps to fetch an array of customers. I wonder what is the best way to extract the data "outside"? Right now the only solution I can think of is using an external array and injecting it with data. I do not know however if this is the best practice as the test array is getting mutated in the process. What could an alternative solution be?

const test = [];

const loadData = (async () => {
  const customersFetched = await fetch(customers);
  const data = await customersFetched.json();
  test.push(data);
})();
Jakub
  • 1
  • 1

1 Answers1

-2
        async function loadData() {
        const customersFetched = await fetch(customers);
       return await customersFetched.json();
         
    }

const data=loadData();

loadData will return the response array.

  • This is just part of the code from the question copy/pasted without modification. It isn't an answer. – Quentin Aug 10 '21 at 20:13