1、json下划线key转驼峰命名
解题外围:
1、正则表达式,/_(\w)/g
2、replace办法
实现:
function convert(jsonObj){
let jsonStr = JSON.stringify(jsonObj);
// 外围正则表白,字符串的replace办法
let formatStr = jsonStr.replace(/_(\w)/g, (all, letter,index,str)=>{
return letter.toUpperCase();
});
return JSON.parse(formatStr)
}
console(convert([{'de_fff_dd':{'n_ff_dd':'222'}},{'ab_cd_ef':'1111'}]))
发表回复