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

根据输出结果,用递归写出方法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]);
  }
 }
}
原文地址:https://www.cnblogs.com/lixiaoran/p/5792444.html