下划线转换驼峰
function toHump(lineStr) {
return lineStr.replace(/\_(\w)/g, function (all, letter) {
return letter.toUpperCase();
});
}
驼峰转换下划线
function toLine(humpStr) {
return humpStr.replace(/([A-Z])/g, "_$1").toLowerCase();
}
测试
let lineStr = 'hello_world';
console.log(toHump(lineStr));
let humpStr = 'helloWord';
console.log(toLine(humpStr));
结果
helloWorld
hello_word
标签:function,转换,下划线,驼峰,humpStr,lineStr
From: https://www.cnblogs.com/qmzbe/p/17151722.html