📅  最后修改于: 2022-03-11 15:03:19.207000             🧑  作者: Mango
const country = 'united kingdom'
const countryArr = country.split(' ')
const newcountry = countryArr
.map((val) => {
const pattern = new RegExp(`^[${val}]`, 'i')
return val.replace(pattern, `${val.charAt(0).toUpperCase()}`)
})
.join(' ')
.trim()
console.log(newcountry)