Capitalize the first letter of every word in a string in JavaScript
Find out how to Capitalize the first letter of every word in a string in JavaScript. In other words, convert the first letter of a string to uppecase using JavaScript.
To capitalize first letter of a string
function capitalize(string) { return string.charAt(0).toUpperCase() + string.slice(1); }
To capitalize first letter of each word in a sentence
function capitalize(string) { string = string.split(" "); for (var i = 0, x = string.length; i < x; i++) { string[i] = string[i][0].toUpperCase() + string[i].substr(1); } return string.join(" "); }