在 Chrome 控制台中显示 jQuery (JS) 对象的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17919911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 20:12:19  来源:igfitidea点击:

Show jQuery (JS) objects' contents in Chrome Console

javascriptjqueryconsole.log

提问by rkeet

Im getting my objects returned in the console as [object Object], however which way I try to have it log all of the contents of the objects I get nothing or errors. I've read a whole lot of questions on SO about this (e.g.: this, this, this, thisand this) but still can't figure it out.

我在控制台中将我的对象返回为[object Object],但是我尝试以哪种方式记录对象的所有内容,但我什么也得不到或出现错误。我已经阅读了很多关于此的问题(例如:thisthisthisthisthis),但仍然无法弄清楚。

I've created some objects by looping through JSON array's using:

我通过循环使用 JSON 数组创建了一些对象:

var tables = {};

$.each(campaigns, function(key, value){
    tables[value] = '';
    var entries = [];
    $.each(data, function(k, v){
        if(v.campaign == value){
            entries.push(v);
        }
    });
    $.extend(tables[value], entries);
});

console.log('tables: ' + tables);

The amount of objects is correct based on the number of objects returned with different conditions and parameters. However, I would like to see what's actually inside them! I don't want to include all sorts of external scripts, do weird and unnecessary loopy-loops, just some simple command I'm overlooking would be awesome!

根据不同条件和参数返回的对象数量,对象数量是正确的。但是,我想看看它们里面到底是什么!我不想包含各种外部脚本,做奇怪和不必要的循环,只是我忽略的一些简单命令会很棒!

How to go about logging objects with something like console.log(someObj);?

如何使用类似的东西记录对象console.log(someObj);

回答by Arun P Johny

Try JSON.stringify()

试试JSON.stringify()

console.log('tables: ' + JSON.stringify(tables));

or in FF and Chrome

或在 FF 和 Chrome 中

console.log('tables: ', tables);

回答by pankaj

If it is a HTML object, then you can see the value with $(tables).text()

如果是 HTML 对象,则可以通过 $(tables).text() 查看值

回答by dalore

Use console.table for tabular data.

将 console.table 用于表格数据。

console.table(tables);