Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Multiple sequential async function calls in <script> that must be awaited, but await doesnt work

So I am trying to load several instances of a lottie animation and the JSONS are on a cdn, the problem is that loading these JSONS is async, and I have to do all of that in tags.

<script>
  // the list of urls
  const urls = ["url", "url", "url", ...]

  // the function that gets each of the jsons, creates an array and returns it
  const getLottieJSONs = (urls) => {
    const lottieJSONs = [];
                  
    for (let i = 0; i < urls.length; i++) {
      $.getJSON(urls[i], (data) => lottieJSONs.push(data))
    }

    return lottieJSONs;
  }

  // creating the instances of the lotties with the retrieved data
  const createLottieInstances = (lottieContainers, lottieJSONs) => {
    const lottieInstances = [];
   
    for (let i = 0; i < lottieContainers.length; i++) {
      lottieInstances.push(bodymovin.loadAnimation({
          container: lottieContainers[i], 
          renderer: "svg", 
          animationData: lottieJSONs[i],
        })
      );
    }

    return lottieInstances;
  }

  const lottieContainers = document.querySelectorAll(".ingredients-lottie-container");
  
  // this does not have the data, before moving on to creating the instances and so it gives empty array to createLottieInstances
  const lottieJSONs = getLottieJSONs(urls); 
  const lottieInstances = createLottieInstances(lottieContainers, lottieJSONs);

  // ... other code that uses the lottie instances ...
</script>

My end goal is to have all instances loaded before I get to the code that is using them with the actual json data.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!