How to make the First Letter Capital in JavaScript
Use the combination of toUpperCase
and slice()
methods to use the toUpperCase
function only on the first letter of the string.
Example:
<script>
function ucfirst(string) {
return string[0].toUpperCase() + string.slice(1);
}
console.log( ucfirst('hello') );
</script>
Output (console): Hello