Steps to get the solution: 1.Loop over the object keys using for..in loop 2. If type of current item is 'object', call flatten method recursively with current item as parameter 3. If type of current item is not an 'object', we can add the current property to result object. Code to flatten the contents of an object :-

let obj = {
  name:'pravin',
  address:{
   country:'india',
   state:{
     city:'pune',
	 srno:'46/1/1/6'
   }
  }
}
const flatten=(obj,result={},keyname="")=>{
 for(var i in obj) {
   if(typeof obj[i]=='object')
   {
     keyname=keyname?(keyname+"_"+i):i;
     flatten(obj[i],result,keyname)
   }   
   else {
     result[(keyname?keyname+"_":"")+i]=obj[i];
   }
 }
 return result;
}
console.log(flatten(obj)); 
/*-------output----*/
/*
        {
           address_country: "india",
	   address_state_city: "pune",
           address_state_srno: "46/1/1/6",
           name: "pravin"
        }
*/