1.驼峰转连字符
var s = "fooStyleCss";
s = s.replace(/([A-Z])/g,"-$1").toLowerCase();
//利用正则进行替换,简洁明了,很棒
2.连字符转驼峰
<script>
var s1 = "style-sheet-base";
var reg = /-(\w)/g
var arr = s1.match(reg)//得到一个匹配的数组
var sr='';
for(let i = 0;i<arr.length;i++){
sr = s1.replace(arr[i],'A')//replace会返回一个新字符串
s1 = sr
}
console.log(sr)
</script>