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

145
Vistas
How to join the elements of an array such that the first letter is capital for all elements in JavaScript?

I want to join the elements of an array separated by commas and the first letter of each element to be capital, this should not affect the object values itself.

For example:

obj= ["apple","orange","lemon"]

Output should be: Apple, Orange, Lemon.

Here is what I have tried and failed with:

obj.charAt(0).toUpperCase().join(', ')

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

0

Here is the code:

let a = ['apple', 'orange', 'lemon'];
let res = a.map(fruit => fruit.charAt(0).toUpperCase() + fruit.slice(1));
console.log(res); // [ "Apple", "Orange", "Lemon" ]
about 4 years ago · Juan Pablo Isaza Denunciar

0

const fruits = ["apple", "orange", "lemon"];

const new_fruits =
  fruits
    .map(x => x.replace(/^[a-z]/, (ch) => ch.toUpperCase()))
    .join(", ");

Replace first letter a-z, uppercase it and finally join with commas. Readability ftw.

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