Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda