js字符串驼峰和下划线互相转换

2023-07-19  本文已影响0人  Coldhands
// 下划线转换成驼峰
function toHump(name) {
    return name.replace(/\_(\w)/g, function(all, letter){
        return letter.toUpperCase();
    });
}
toHump('a_b_c') // aBC


// 驼峰转换下划线
function toLine(name) {
  return name.replace(/([A-Z])/g,"_$1").toLowerCase();
}
toLine('aBcdEfg') //a_bcd_efg
上一篇 下一篇

猜你喜欢

热点阅读