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

506
Vistas
How to get and return each last character of array to be in uppercase using javascript?

I have the following array variable, I want to return the given array where each of element's last character to be in Uppercase using javascript, I have tried like below, but I am getting undefined unfortunately, Could you please anyone help me to get the desired output like below. Thanks in advance.

Desired Output: [onE, twO, threE, fouR]

var arr = ['one', 'two', 'three', 'four'];

var res = arr.map((item) => {
    item.substr(arr.length) + item.charAt(arr.length -1).toUpperCase();
});
console.log(res);//[undefined, undefined, undefined, undefined]
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

you are missing a return statement:

var res = arr.map((item) => {
    return item.slice(0,-1)+item.slice(-1).toUpperCase()
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can also skip curly brackets and return keyword:

const arr = ['one', 'two', 'three', 'four'];

const res = arr.map(item => 
    item.substring(0, item.length - 1) +
    item.charAt(item.length - 1).toUpperCase()
)

console.log(res);

Also notice that String.prototype.substr is mentioned as deprecated (you can use substring instead).

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