对象的扁平化处理
var obj = {
'A': 1,
'B.A': 2,
'B.B': 3,
'CC.D.A': 4,
'CC.D.F': 5,
}
var pinjie = function(str, obj,value) {
if(str.includes('.')){
let index = str.indexOf('.')
if(str.slice(index + 1).includes('.')){
obj[str.slice(0,index)] = {...obj[str.slice(0,index)]}
pinjie(str.slice(index + 1), obj[str.slice(0,index)], value)
}else{
obj[str.slice(0,index)] = {...obj[str.slice(0,index)]}
obj[str.slice(0,index)][str.slice(index+1)] = value
}
}else{
obj[str] = value
}
}
var resaultObj = {}
for(let i in obj){
pinjie(i, resaultObj, obj[i])
}
console.log(JSON.stringify(resaultObj))