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

102
Visualizações
Filter array of object based on date range

This problem is quite easy but I still can't handle it. I have an array of object let's say something like:

const array = [{id:1,created_at: 2022-03-14T16:40:10.000000Z}, {id:2, created_at:2022-03-15T16:40:10.000000Z}

I want to filter element using moment.js, and having back only the element that have date of creation of today.

What i want to achieved is something like this:

const filtered = array.filter((item)=> item.created_at >= startOfToday && item.created_at <= endOfToday

Filtered will look like: [0]{id:2, created_at:2022-03-15T16:40:10.000000Z}

Thanks in advance for any tips/answers.

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

0

Can you use statOf and endOf to make your filter work?

const filtered = array.filter(item => {
  const createdAt = moment(item.created_at)
  const startOfToday = moment().startOf('day')
  const endOfToday = moment().endOf('day')
  return createdAt.isBetween(startOfToday, endOfToday)
})
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