Posts Learn Components Snippets Categories Tags Tools new About
/

JavaScript uppercase first letter and each word in es6

Learn how to JavaScript uppercase first letter and each word in es6

Created on Nov 23, 2021

25 views

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(' ')

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

)