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

137
Visualizações
How to filter items from an array of day values where a day's integer value has to match any timestamp from a second array of event items?

In JSX I am mapping through a number of days that I have calculated in a month:

  {range(daysInMonth).map((i) => (
          <div
            className="day-cell day-cell--in-month"
            key={i}
          >
            {i + 1}
          </div>
        ))}

I then have a array of events coming from an api:

const events = [
{
date: timestamp,
description: "Meeting with friends"
}
//More events//
]

How can I map through the array of events and match the event timestamp to the current timestamp of the date for the daysInMonth that is being mapped and then display the event description?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In case the above comment's assumption ...

"the daysInMonth is just a number, for example for Feb it would be 28." ... thus, one can assume the timestamp/date value of an events item is an integer as well?

... applies, one could implement the preceding filter task in collaboration with some.

const events = [{
  date: timestamp,
  description: "Meeting with friends"
}/*, { More events }*/];


{
  range(
    
    daysInMonth
    
  ).filter(dayValue =>
    
    events.some(({ date }) => date === dayValue)
    
  ).map(dayValue => (
    <div
      className="day-cell day-cell--in-month"
      key={dayValue}
    >
      {dayValue + 1}
    </div>
  ))
}

Edit

"... thus, one can assume the timestamp/date value of an events item is an integer as well?" – Peter Seliger

"... it's a timestamp from a MySQL database." – adherb

"... then within the already provided filter code of my answer one has to get the day from each events item's date value in order to make it comparable to the integer value of each daysInMonth item." – Peter Seliger

const events = [{
  date: timestamp,
  description: "Meeting with friends"
}/*, { More events }*/];


{
  range(

    daysInMonth

  ).filter(dayValue =>
    events.some(({ date }) =>
      new Date(date).getDay() === dayValue
    )
  ).map(dayValue => (
    <div
      className="day-cell day-cell--in-month"
      key={dayValue}
    >
      {dayValue + 1}
    </div>
  ))
}
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