[Vuejs]-Vue JS – Check if all items in an array are loaded before firing a function

0πŸ‘

Is it possible to check whether the prop β€˜trashData’ has loaded all
the items it needs from the api before firing the relevant function to
create the markers?

You can use Promise.all() : you push all your requests to the API in an array of Promises, and then you wait for it with Promise.all().

const promiseN = new Promise((resolve, reject) => {
  getDataFromApi().then((result) => {
    resolve(result);
}});

Promise.all([promise1, ..., promiseN]).then((values) => {
  console.log(values);
});

Leave a comment