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

103
Vistas
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 Respuestas
Responde la pregunta

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 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