js把下划线字符串转为大驼峰字符串
作者:互联网
let str = "zifu_chuan_chang"
function func(str)
{
let arr = str.split('_')
let resStr = arr.reduce(function(prev, cur){
let str = prev + cur.slice(0, 1).toUpperCase() + cur.slice(1)
return str
})
// 转小驼峰这一行不需要
resStr = resStr.slice(0, 1).toUpperCase() + resStr.slice(1)
return resStr
}
console.log(func(str))
标签:arr,slice,下划线,resStr,js,let,str,字符串,cur 来源: https://www.cnblogs.com/zxcv123/p/16068960.html