This content originally appeared on CodeSource.io and was authored 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.
The post Capitalize the first letter of each word in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Prince Chukwudire
Prince Chukwudire | Sciencx (2021-02-18T17:23:49+00:00) Capitalize the first letter of each word in Javascript. Retrieved from https://www.scien.cx/2021/02/18/capitalize-the-first-letter-of-each-word-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.