第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

怎么遞歸輸出這個(gè)對(duì)象?

怎么遞歸輸出這個(gè)對(duì)象?

慕妹3242003 2019-04-08 11:18:48
varorz={it:{facebook:{apple:{google:{twitter:{}},microsoft:{}}}},china:{}};functionobjLength(obj){varj=0;for(iinobj){j++;}returnj;}functionre(ja,num,tree,jn){if(objLength(ja)==0){return;}if("undefined"==typeofnum){num=0;}if("undefined"==typeoftree){tree=[];}if("undefined"!=typeofjn){tree.push(jn);}num++;fo(ja,tree,num);functionfo(a,b,c){for(xina){if(b.length>0){console.log(c+":"+b+","+x);}else{console.log(c+":"+x);}re(a[x],c,b,x);}}}re(orz);/***為什么結(jié)果是:*1:it*2:it,facebook*3:it,facebook,apple*4:it,facebook,apple,google*5:it,facebook,apple,google,twitter*4:it,facebook,apple,google,microsoft*1:it,facebook,apple,google,china*而不是*1:it*2:it,facebook*3:it,facebook,apple*4:it,facebook,apple,google*5:it,facebook,apple,google,twitter*4:it,facebook,apple,microsoft*1:china**/修改
查看完整描述

2 回答

?
拉丁的傳說(shuō)

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊

varorz={
it:{
facebook:{
apple:{
google:{
twitter:{}
},
microsoft:{}
}
}
},
china:{}
};
varresult=[];
functionre(obj,prev){
Object.keys(obj).forEach(function(item){
varhehe='';
if(obj[item]instanceofObject&&!(obj[item]instanceofArray)){
//如果數(shù)組也算,使用下邊的條件
//if(obj[item]instanceofObject){
hehe=(prev.length?prev+','+item:item);
result.push(hehe);
re(obj[item],hehe);
}
});
}
re(orz,'');
console.log(result);
                            
查看完整回答
反對(duì) 回復(fù) 2019-04-08
  • 2 回答
  • 0 關(guān)注
  • 364 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)