Capitalize First Letter in a String with JavaScript

In creating a function for a client, I ran into an issue where I wanted to capitalize the first letter in a string with JavaScript, or in other words, uppercase the first letter in a string with JavaScript. The solution is quite simple, all you need to do is use the following function:

function capitalize(word){
 return word && word[0].toUpperCase() + word.slice(1);
}

Then, when you want to capitalize the first letter in a particular string, run the following:

var word = 'wplauncher plugins';

// this will return Wplauncher plugins
var capitalized_word = capitalize(word);

Leave a Reply

Your email address will not be published. Required fields are marked *