我从 API 收到这样的数据
var myObj = {'name':'ahmed','age':37,'tools':{'dev1':"macbook",'dev2':"iphone",'dev3':"tablet"},'gender':'male'};
使键值对注意嵌套对象的最佳方法是什么?
更新 感谢您的回答,如果我不想展平我的对象
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));
结果
{ name: 'ahmed',
age: 37,
tools: { dev1: 'macbook', dev2: 'iphone', dev3: 'tablet' },
gender: 'male' }