How To Capitalize The First Letter of String In JavaScript

Reading Time: 2 minutes
713 Views

Inside this article we will see the concept i.e How To Capitalize The First Letter of String In JavaScript Tutorial. Article contains the classified information about JavaScript Program to Convert the First Letter of a String.

If you are looking for a solution i.e Javascript How To Make capitalize the first letter of a string then this article will help you a lot for this. Tutorial is super easy to understand and implement it in your code as well.

Example (Normal String)

welcome to online web tutor

Example (Capitalize First Letter of String)

Welcome to online web tutor

Read More: How To Generate And Download CSV File in Javascript Tutorial

Let’s get started.

Application Programming

Create a folder say capital-letter in your localhost directory. Create a file index.html into it.

//...

<script>
    let string = 'welcome to online web tutor';

    console.log(ucFirst(string));

    function ucFirst(string) 
    {
        // Output: Welcome to online web tutor
        return string.charAt(0).toUpperCase() + string.slice(1);
    }
</script>
  
//...

Application Testing

Open browser and type your application URL:

URL: http://localhost/capital-letter/index.html

Read More: JavaScript How To Call a Function Repeatedly Every 5 Seconds

Output

Welcome to online web tutor

We hope this article helped you to learn How To Capitalize The First Letter of String In JavaScript in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.