这道题面试前端,没人答出来!

根据输出结果,用递归写出方法printAll
var user = {
username: "lilei",
phone: "158",
description: "i am a boy",
like: {
movie: "homeland",
game: "cs",
sport:"basketball"
}
};
printAll(user);
输出:
username:lilei
phone:158
description:i am a boy
movie:homeland
game:cs
sport:basketball

 

function printAll(s){
 for(var i in s){
  if(typeof s[i]=="object"){
   printAll(s[i])
  }else{
   console.log(i+":"+s[i]);
  }
 }
}

 

posted @ 2016-08-21 12:10  然然1907  阅读(137)  评论(0编辑  收藏  举报