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

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

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

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