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

150
Views
How to filter an array by year using the format DD/MM/YYYY

I have this code below :

  var array1 = ['10/10/2020','11/10/2020','12/10/2020','10/10/2021','12/10/2021','12/10/2021'];

  <select id="dates">
    <option>2021</option>
    <option>2020</option>
  </select>

I would like to know how can I filter the array1 to return just the values from the year selected. Any Suggestion ?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I hope this code helping you

var result = array1.filter(o=>o.indexOf('2021') != -1)
about 4 years ago · Juan Pablo Isaza Report

0

You can take help from Array filter method

const result = array1.filter(date => date.includes(2021))

above result will give you all the dates with the year 2021

about 4 years ago · Juan Pablo Isaza Report

0

Listen for the change event and use Array.filter to filter out the items whether the year isn't the same as the select's value.

You can get the year by splitting the string by a slash and getting the third item.

var array1 = ['10/10/2020', '11/10/2020', '12/10/2020', '10/10/2021', '12/10/2021', '12/10/2021'];

dates.addEventListener("change", function(){
  var filtered = array1.filter(e => e.split("/")[2] == this.value)
  console.log(filtered)
})
<select id="dates">
  <option>2021</option>
  <option>2020</option>
</select>

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!