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

135
Vistas
Is there a way I could iterate through dates in an array and add them to this object?

I'm using a jQuery calendar I found online and I'm struggling to add the dates into it. I am able to iterate through the API response and push them to an array. But from there I am struggling to add it to the calendar.

        $(function(){
          $("#calendar").simpleCalendar();
        });

        var dates = [];
        var descriptions = [];

        for(i = 0; i < result['data']['holidays'].length; i++){
          let date = result['data']['holidays'][i]['date']['iso'];
          dates.push(new Date(date));
          descriptions.push(result['data']['holidays'][i]['description']);
        }

        console.log(dates[34] + " " + descriptions[34]);
                
        $("#calendar").simpleCalendar({       
          // Events displayed
          displayEvent:true,
          // Dates of the events                  
          events: [           
            {
              startDate: dates[1],
              endDate: dates[1],
              summary: descriptions[1]
            }
          ]
        });       

I've tried adding it inside the loop and putting the array key as "i" but this hasn't worked for me.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Fill the events variable inside of you loop, and use it directly on the json.

    $(function(){
      $("#calendar").simpleCalendar();
    });

    var eventsArr = [];

    for(i = 0; i < result['data']['holidays'].length; i++){
      let date = result['data']['holidays'][i]['date']['iso'];
      eventsArr.push({
          "startDate": new Date(date),
          "endDate"  : new Date(date),
          "summary"  : result['data']['holidays'][i]['description']
      });
    }

    $("#calendar").simpleCalendar({       
      // Events displayed
      displayEvent:true,
      // Dates of the events                  
      events: eventsArr
    });       
about 4 years ago · Juan Pablo Isaza Denunciar
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