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

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

0

I hope this code helping you

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

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 Denunciar

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