<script type="text/javascript">
let str = 'get-element-by-id'
function trans(ele) {
let eleArr = ele.split('-')
let newEle = ''
eleArr.map((o, i) => {
if(i > 0) {
o = o.charAt(0).toUpperCase() + o.slice(1)
}
newEle += o
})
return newEle
}
function trans1(ele) {
let eleArr = ele.split('-')
for(let i = 1; i < eleArr.length; i++) {
eleArr[i] = eleArr[i].charAt(0).toUpperCase() + eleArr[i].substr(1, eleArr[i].length - 1)
}
return eleArr.join('')
}
console.log(trans(str))
console.log(trans1(str))
</script>
网友评论