how i can view array structure in javascript with alert()
A very basic approach is |
|||
|
EDIT: Firefox and Google Chrome now have a built-in I tend to use the jQuery-json plugin as follows:
This prints the array in a format like
However, for debugging your Javascript code, I highly recommend Firebug It actually comes with a Javascript console, so you can type out Javascript code for any page and see the results. Things like arrays are already printed in the human-readable form used above. Firebug also has a debugger, as well as screens for helping you view and debug your HTML and CSS. |
||||
|
pass your js array to the function below and it will do the same as php print_r() function
|
||||
You can use |
|||
|
If this is for debugging purposes, I would advise you use a JavaScript debugger such as Firebug. It will let you view the entire contents of arrays and much more, including modifying array entries and stepping through code. |
|||
|
I'd recommend using toString(). Ex. |
|||
|
You could write a function that will convert and format this array as string. Even better: use FireBug for debugging instead of alerts. |
|||
|
console.log
-- it's great for introspection of JavaScript objects. – Deniz Dogan Jun 9 '10 at 14:15console.debug
would actually work better. – Matt Ball Jun 9 '10 at 14:25