first letter caps in javascript

To capitalize the first letter of a string in JavaScript, you can use the charAt and toUpperCase methods. Here's an example:

index.tsx
let str = "hello world";
str = str.charAt(0).toUpperCase() + str.slice(1);
console.log(str); // Output: "Hello world"
118 chars
4 lines

In this code snippet, we first declare a variable str and assign it the value "hello world". Then, we use the charAt method to get the first character of the string (which is "h"), call the toUpperCase method to convert it to uppercase, and concatenate it with the rest of the string using the slice method.

The resulting string has the first letter capitalized, as desired.

gistlibby LogSnag