Home / Snippets / JavaScript uppercase first letter and each word in es6
JavaScript uppercase first letter and each word in es6 cover

JavaScript uppercase first letter and each word in es6

532

3 years ago

0 comments

In this short snippet, you will learn how to uppercase the first letter and each word in JavaScript ES6.

JavaScript uppercase first letter es6


To uppercase the first letter you can simply uppercase the 1st character of the word and then slice the remaining.
let word = 'what in the world';
let capitalizedWord = word[0].toUpperCase() + word.slice(1)

Capitalize first letter of each word in a string


To capitalize the first letter of each word in a string you can first split the sentence, loop through it using a map, and apply the capitalization then finally join it back.
let word = 'what in the world';
let capitalizedWord = word[0].toUpperCase() + word.slice(1)

'what in the world'
	.split(" ")
	.map(arr => arr.charAt(0).toUpperCase() + arr.slice(1))
	.join(' ')
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this