coco

随心。。。随性。。。随行。。。

  博客园  ::  ::  ::  ::  :: 管理

for...in 循环

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"));

Object.getOwnPropertyNames(o)

var obj = { age: 18, fname: "Rand ", lname: "McKinnon" };
Object.getOwnPropertyNames(obj).forEach(function (i, value) { console.log(i + ":" + value + "\n") });

Object.keys(o)

Object.keys(obj).forEach(function(i,value){console.log(i+":"+value+"\n")});

  

posted on 2015-05-18 21:29  深谷&幽兰  阅读(145)  评论(0编辑  收藏  举报