Capitalize first letter of each word in JS

前端 未结 17 713
闹比i
闹比i 2021-01-03 23:26

I\'m learning how to capitalize the first letter of each word in a string and for this solution I understand everything except the word.substr(1) portion. I see that it\'s a

17条回答
  •  没有蜡笔的小新
    2021-01-04 00:11

    Using ES6

    let captalizeWord = text => text.toLowerCase().split(' ').map( (i, j) => i.charAt(0).toUpperCase()+i.slice(1)).join(' ')
    
    captalizeWord('cool and cool')
    

提交回复
热议问题