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(' ')
Leave a reply