How to inspect Javascript Objects

后端 未结 8 563
半阙折子戏
半阙折子戏 2020-12-07 10:31

How can I inspect an Object in an alert box? Normally alerting an Object just throws the nodename:

alert(document);

But I want to get the p

8条回答
  •  广开言路
    2020-12-07 10:54

    var str = "";
    for(var k in obj)
        if (obj.hasOwnProperty(k)) //omit this test if you want to see built-in properties
            str += k + " = " + obj[k] + "\n";
    alert(str);
    

提交回复
热议问题