Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report

0

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

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

about 4 years ago · Santiago Trujillo Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!