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

146
Vistas
How compare array of dates with an date string to find count of same days in JavaScript?

I tried this method to check duplicate date in the array with date string array, but didn't work Please anyone can help..

    const dateArray = ["2000-07-13","03/24/2000", "June 7 2021"]
    const compaingDate =new Date("2000-06-13")
    let countOfDays=0
    for(let sameDate of dateArray){
        if(compaingDate.getDate()===sameDate.getDate()){
            countOfDays+=1
        }
    }
    console.log(countOfDays);

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

0

You never convert the array of strings into an array of dates:

    const dateArray = ["2000-07-13","03/24/2000", "June 7 2021", "June 13 2006"]
    const compaingDate =new Date("2000-06-13")
    let countOfDays=0
    for(let sameDate of dateArray){
    sameDate = new Date(sameDate)
        if(compaingDate.getDate()===sameDate.getDate()){
            countOfDays+=1
        }
    }
    console.log(countOfDays);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Maybe this is what you are looking for?

A shorten version:

const dateArray = ["2000-07-13", "03/24/2000", "June 7 2021"]
const compaingDate = new Date("2000-06-13")
let countOfDays = 0
dateArray.forEach(item => {
  if (new Date(item).getDate() === compaingDate.getDate())
    countOfDays++
})
console.log(countOfDays);

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