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

129
Vistas
Find all unique values in array and than split it and return something else

My goal is to find all the unique years in this array and than return it as a array. I have almost done it but cant figure out how I will return the split value.

function findUniqueYears() {
  const arr = ['1973-11-01', '2001-01-01', '1999-10-01', '2007-10-01', '2016-06-01', '2005-08-01', '1973-09-01', '1979-12-01', '2001-08-01'];
  for (var i = 0; i < arr.length; i++) {
    for (var j = i + 1; j < arr.length; j++) {
      if (arr[i].split("-")[0] === arr[j].split("-")[0]) {
        arr.splice(j, 1);
      }
    }
  }
  console.log(arr)
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This should do

const findUniqueYears = (arr) => Array.from(new Set(arr.map(item => item.split('-')[0])))
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use the function map to iterate via each element in the array then you can easily split date by '-' return 0 value and cast it to Set.

function findUniqueYears() {
  const arr = ['1973-11-01', '2001-01-01', '1999-10-01', '2007-10-01', '2016-06-01', '2005-08-01', '1973-09-01', '1979-12-01', '2001-08-01'];
  return new Set(arr.map((el) => el.split('-')[0]))
}

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