get-element-by-id转成GetElementById
const str = 'get-element-by-id'
function upperCase(str,method){
let temp = str.split(`${method}`)
for(let i = 0;i < temp.length; i++){
temp[i] = temp[i].charAt(0).toUpperCase()+temp[i].substr(1)
}
return temp.join('')
}
upperCase(str,'-')
// GetElementById
说明:
字符串.split(x)可以把字符串转成数组 x为以什么字符进行切割
charAt(x) 取字符串中的某个元素 x为取某个小角标字符
toUpperCase() 转成大写
substr(x,y) 对字符串进行切割操作,x起始位置 ,y结束位置 y不传值时默认到结尾
join(x) 数组转字符串,x为以什么字符进行连接