Capitalize first character of a string in JavaScript

JavaScript doesn’t have a built-in function to convert first character in small case. But you can convert first character in upper case of a string into upper case with using code mentioned in example. Example of capitalize method is mentioned below: Code


<script>
var str = "hello world";
var capitalized = str.charAt(0).toUpperCase() + str.slice(1);
console.log(capitalized);  // Output: Hello world
</script>