代碼走你javascript
// 下劃線轉換駝峯 function toHump(name) { return name.replace(/\_(\w)/g, function(all, letter){ return letter.toUpperCase(); }); } // 駝峯轉換下劃線 function toLine(name) { return name.replace(/([A-Z])/g,"_$1").toLowerCase(); } // 測試 let a = 'a_b2_345_c2345'; console.log(toHump(a)); let b = 'aBdaNf'; console.log(toLine(b));