programming-examples/js/String/Capitalize each word in the string.js
2019-11-15 12:59:38 +01:00

5 lines
181 B
JavaScript

function capitalizeWords(str)
{
return str.replace(/\w\S*/g, function(txt){return txt.substr(0).toUpperCase();});
}
console.log(capitalizeWords('js string exercises'));