To convert the first character in a string to uppercase in JavaScript, you can use string manipulation methods such as charAt()
and toUpperCase()
.
In this example,
str1
with a value of "hello world"
.str1
using the charAt()
method.toUpperCase()
method.let str1 = "hello world";
let modifiedStr1 = str1.charAt(0).toUpperCase() + str1.slice(1);
console.log("Modified string is: " + modifiedStr1);
Modified string is: Hello world
In this example,
str2
with a value of "javascript"
.str2
using the charAt()
method.toUpperCase()
method.let str2 = "javascript";
let modifiedStr2 = str2.charAt(0).toUpperCase() + str2.slice(1);
console.log("Modified string is: " + modifiedStr2);
Modified string is: Javascript
In this tutorial, we learned How to convert First Character in String to Uppercase in JavaScript language with well detailed examples.