Open Genzhen opened 3 years ago
'kuai-shou-front-end'.replace(/(\b\w)|(-)/g, (val, p1) => p1 ? p1.toLocaleUpperCase() : '')
var str = "get-element-by-id";
function s(str) {
return str.replace(/\-\w/g, (x) => {
return x.slice(1).toUpperCase();
});
}
console.log(s(str));
"get-element-by-id".replace(/(?:^|-)([a-z]{1})/g, (a, b) => b.toUpperCase())
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。