Open fudx opened 1 year ago
function flatten(data) {
// todo
const ans = {}
const dfs = (data,preFix)=>{
if(typeof data === 'object') {
for(let i in data) {
preFix.push(i)
if(typeof data[i] === 'object'){
dfs(data[i],preFix)
} else {
ans[preFix.join('.')] = data[i]
}
preFix.pop()
}
}
}
dfs(data,[])
console.log(ans)
return ans
}