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

147
Vistas
I need to create a method that upper cases only the first character of a string (Javascript)

My incorrect method:

String.prototype.tittle = function(){
    return (this.split('')[0].toUpperCase()) + ((Array(this)).shift())
}

console.log('onimusha'.tittle())   // it returns Oonimusha, was expected Onimusha

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Based on your expected output, you want this.

String.prototype.tittle = function(){
    return this[0].toUpperCase() + this.slice(1)
}

console.log('onimusha'.tittle())   // it returns Oonimusha, was expected Onimusha

about 4 years ago · Santiago Trujillo Denunciar

0

String.prototype.tittle = function() {
    return this.charAt(0).toUpperCase() + this.substring(1)
}

console.log('onimusha'.tittle())

about 4 years ago · Santiago Trujillo Denunciar

0

try:

String.prototype.tittle = function() {

  // break up string into individual characters
  let chars = this.split('');

  // uppercase the first character and save it back to the first element 
  chars[0] = chars[0].toUpperCase();

  // then piece back the string and return it
  return chars.join('');
}

console.log('hello'.tittle()); // Hello
about 4 years ago · Santiago Trujillo 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