Capitalize first letter of each word in JS

前端 未结 17 746
闹比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:04

    Just map through if an array set the first letter as uppercase and concatenate with other letters from index 1. The array isn't your case here.

    const capitalizeNames = (arr) => {
    arr.map((name) => {
        let upper = name[0].toUpperCase() + name.substr(1)       
        console.log(upper)
    })
    

    }

提交回复
热议问题