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

104
Vistas
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 Respuestas
Responde la pregunta

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