Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show jQuery (JS) objects' contents in Chrome Console

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

like image 714
rkeet Avatar asked Jul 29 '13 09:07

rkeet


People also ask

How do I view objects in console?

Answer: Use console. log() or JSON. stringify() Method You can use the console. log() method, if you simply wants to know what's inside an object for debugging purpose. This method will print the object in browser console.

How do you print an object object?

stringify() method is used to print the JavaScript object. JSON. stringify() Method: The JSON. stringify() method is used to allow to take a JavaScript object or Array and create a JSON string out of it.

How do you console an object in JavaScript?

Console object In JavaScript, the console is an object which provides access to the browser debugging console. We can open a console in web browser by using: Ctrl + Shift + I for windows and Command + Option + K for Mac. The console object provides us with several different methods, like : log()


1 Answers

Try JSON.stringify()

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

or in FF and Chrome

console.log('tables: ', tables);
like image 137
Arun P Johny Avatar answered Oct 19 '22 17:10

Arun P Johny