Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

0

I hope this code helping you

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

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda