const input = {
a: {
b: 'hello',
c: {
d: 'world'
}
},
e: 'hello world'
}
function flatternObject(obj,parentKey='',result={}){
for(const key in obj){
const newKey = parentKey ? `${parentKey}.${key}` :key;
if(typeof obj[key] === 'object' && obj[key] !== null){
flatternObject(obj[key], newKey, result);
} else {
result[newKey] = obj[key];
}
}
return result
}
const output = flatternObject(input);
console.log(output)