tags:

views:

69

answers:

4

how i can view array structure in javascript with alert()

+6  A: 

A very basic approach is alert(arrayObj.join('\n')), which will display each array element in a row.

Humberto
+1  A: 

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.

Justin Ethier
A: 

You could write a function that will convert and format this array as string. Even better: use FireBug for debugging instead of alerts.

Darin Dimitrov
+1  A: 

I tend to use the jQuery-json plugin as follows:

alert( $.toJSON(myArray) );

This prints the array in a format like

[5, 6, 7, 11]

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.

Eli Courtwright