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

109
Visualizações
How to modify strings in js array

It was supposed to capitalize first characters of each string but it doesn't. Please tell me how I can solve this problem.

    let array = ["string1", "string2", "string3", "string4"];
    let btn = document.getElementById("btn");

    array.forEach(function (item) {
      item.charAt(0).toUpperCase();
    })

    btn.addEventListener("click", function () {
      document.getElementById("p").innerHTML = array.join(" ")
    })```
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are getting the first letter and converting it to uppercase, but you aren't doing anything with it.

You need to concatenate the rest of the string to the first character, then reassign back.

let array = ["string1", "string2", "string3", "string4"];

array.forEach(function(item, i) {
  array[i] = item.charAt(0).toUpperCase() + item.substring(1)
})

console.log(array.join(" "))

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