Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print all variables?

Tags:

javascript

I want to do a function that can be used a lot in debugging that print all variables with their values. It would alert:
x=3
y=2

The function would be like that :
Exemple :

var text='';
for(var a=0;a<allVariables;a++)
{
    text+=nameOfVariable + " = " + valueOfVariable + "/n";
}
alert(text);
like image 379
user1342369 Avatar asked Dec 12 '22 03:12

user1342369


2 Answers

This will probably do what you're looking for:

console.dir(window);
like image 87
David Gorsline Avatar answered Jan 04 '23 12:01

David Gorsline


You should use console methods, it's the best for debugging. Quite all modern browsers have the console, and you can use better debugging tools like firebug for firefox. Then a simple console.log(allVariables) and it is all shown in the console.

like image 45
Tronix117 Avatar answered Jan 04 '23 10:01

Tronix117