Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda