I have received data from API like this
var myObj = {'name':'ahmed','age':37,'tools':{'dev1':"macbook",'dev2':"iphone",'dev3':"tablet"},'gender':'male'};
What is the best way to make it key-value pairs note that there are nested objects?
update Thanks for the answer this is if I don't want to flatten my object
var myObj = {'name':'ahmed','age':37,'tools':{'dev1':"macbook",'dev2':"iphone",'dev3':"tablet"},'gender':'male'};
function unQuoteKeys(obj, newObj ={}){
Object.keys(obj).forEach(key => {
newObj[key] = obj[key]
});
return newObj
}
console.log(unQuoteKeys(myObj));
result
{ name: 'ahmed',
age: 37,
tools: { dev1: 'macbook', dev2: 'iphone', dev3: 'tablet' },
gender: 'male' }