How to capitalize string js (Javascript Scripting Language)

Asked by: D.L. Medioli
Edit Question Icon
Edit
Follow Icon
Report Icon
Report

Explain Below What Do You Want to report!


Available Answers: 1

Pradip Luthra (PLATING MACHINE OPERATOR Data Management) From: Chandigarh/India
1
With performance metrics...
2
3
// 10,889,187 operations/sec
4
function capitalizeFirstLetter(string) {
5
    return string[0].toUpperCase() + string.slice(1);
6
}
7
8
// 10,875,535 operations/sec
9
function capitalizeFirstLetter(string) {
10
    return string.charAt(0).toUpperCase() + string.slice(1);
11
}
12
13
// 4,632,536 operations/sec
14
function capitalizeFirstLetter(string) {
15
    return string.replace(/^./, string[0].toUpperCase());
16
}
17
18
// 1,977,828 operations/sec
19
String.prototype.capitalizeFirstLetter = function() {
20
    return this.charAt(0).toUpperCase() + this.slice(1);
21
}
22
Upvote Icon5
Comment IconComment
Follow Icon
Report IconReport

Explain Below What Do You Want to report!


Explain Below What Do You Want to comment!




More Questions


Would you like to join Ask Sawal!

Why?

  1. Ask Sawal is a fast growing question and answer discussion forum.

  2. 15 lakh+ questions were answered by our Ask Sawal Members.

  3. Each day 1000s of questions asked & 1000s of questions answered.

  4. Ask any question and get answer from 2.5 Lakh+ Ask Sawal Members.

  5. Constant moderation and reporting option makes questions and answers spam free.

  6. And also, we have free blogging platform. Write an article on any topic.

  7. We have 10000+ visitors each day. So a beneficial platform for link building.

  8. We are allowing link sharing. Create backlinks to your blog site or any site.

  9. Gain extra passive income by sharing your affiliate links in articles and answers.