循环
var obj = { age: 18, fname: "Rand ", lname: "McKinnon" };function showProps(obj, objName) { var result = ""; for (var prop in obj) { result += objName + "." + prop + " = " + obj[prop] + "\n"; } return result;}console.log(showProps(obj, "person"));
var obj = { age: 18, fname: "Rand ", lname: "McKinnon" };Object.getOwnPropertyNames(obj).forEach(function (i, value) { console.log(i + ":" + value + "\n") });
Object.keys(obj).forEach(function(i,value){console.log(i+":"+value+"\n")});
posted on 2015-05-18 21:29 阅读( ...) 评论( ...)