Capitalize the first letter of each word in Javascript
Posted on: February 18, 2021 by Prince Chukwudire
In this guide, we will look at writing a function that capitalizes the first letter of every word in JavaScript.
const capitalize = value => {
if (!value) return "";
return value
.split(" ")
.map(val => val.charAt(0).toUpperCase() + val.slice(1))
.join(" ");
};
So basically we split the given string, using the space as a base. We went ahead to extract the first character using the charAt
this we then change to an uppercase letter.
Share on social media
//