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

178
Vistas
Match variable value to array's index to get month
example of getDepart date format

getDepart = 2022-04-29

desired result 29 APR, 2022

const getStringDepart = () => {

    const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", 
    "NOV", "DEC"];
    const departArray = getDepart.split("-");
    const departDay = departArray[2];
    const departYear = departArray[0];
    const departMonth = ????????????
    const departString = `${departDay} ${departMonth}, ${departYear}`;
    return departString;

}

I'm trying to turn my YYYY-MM-DD string date format to a DD mon, YYYY string. I was thinking about using an array with the months and matching the month number to it's index, but I can't find a way to do so.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You just need to pass the month - 1 on your array. It should return the month properly.

getDepart = '2022-04-29';

const getStringDepart = () => {
  const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
  const departArray = getDepart.split("-");
  const departDay = departArray[2];
  const departYear = departArray[0];
  const departMonth = departArray[1];
  const departString = `${departDay} ${months[Number(departMonth) - 1]}, ${departYear}`;
  return departString;
}

function test() {
  console.log(getStringDepart())
}

Output:

output

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