下划线与驼峰互转

1.下划线转化为驼峰

let newKey = 'obj_key'
newKey = newKey.replace(/_([a-z])/g, (p, m) => m.toUpperCase())

2.驼峰转化下划线

let newKey = 'objKey'
newKey = newKey.replace(/([A-Z])/g, (p, m) => `_${m.toLowerCase()}`)

 

你可能感兴趣的:(前端)