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);/***为什么结果是:*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**/修改
相关分类