Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!