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