13

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, this and this) but still can't figure it out.

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

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

Community
  • 1
  • 1
rkeet
  • 3,406
  • 2
  • 23
  • 49
  • 1
    Is `console.log('tables: ', tables)` working better? Don't force a toString() on the object, the console should give you a nice object browser. – Thilo Jul 29 '13 at 09:08
  • Yep! Got the answer already. ;) I've been ridiculously stupid and have been mixing the `+` and `,` in the `console.log('bla', blop)` vs the `console.log('bla' + blop)` for weeks! – rkeet Jul 29 '13 at 09:12

3 Answers3

30

Try JSON.stringify()

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

or in FF and Chrome

console.log('tables: ', tables);
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • Oh very nice, straight away get to see what's in the tables, and noticing some errors in my code already! :) Thanks a lot! The edit to your answer though: "or in FF and Chrome `console.log('tables: ', tables)`... I've been mixing up the `+` and `,` for weeks now! UGH!!! **facepalm** – rkeet Jul 29 '13 at 09:10
0

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

pankaj
  • 1,643
  • 4
  • 22
  • 35
0

Use console.table for tabular data.

console.table(tables);
dalore
  • 5,594
  • 1
  • 36
  • 38