var_dump for JavaScript – JavaScript equivalent of PHP var_dump

Here’s a handy little JavaScript function that lets you dump the contents of an array, just like you would using var_dump in PHP.

function dump(obj) {
 var out = '';
 for (var i in obj) {
 out += i + ": " + obj[i] + "\n";

To use, call the function and pass it the array you want to dump. For example:


The array will appear on screen in an alert window.
You can also change the alert to console.log to make the output display in the browsers debug console. for example:




Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *