根据输出结果,用递归写出方法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]);
  }
 }
}

 

相关文章:

  • 2021-04-17
  • 2021-11-12
  • 2021-06-13
  • 2022-01-22
  • 2021-08-05
  • 2021-07-02
  • 2021-09-08
  • 2021-04-09
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2021-09-25
  • 2021-06-02
相关资源
相似解决方案