I have an array
var arr = [1,2,3,4,5,6,7,8,9,10];
How to display all items of the array using an alert box?
I have tried : alert(arr);
and it shows nothing.
Edit: I want display this array like php print_r
function.
output needed like: array["key" => "value", "key" => "value", ...];
You could also use the JavaScript function toString()
.
alert(arr.toString());
To show them in csv, you can use .join(",")
along with array object:
alert(arr.join(", "));
for printing individually:
$.each(arr, function( index, value ) {
alert( value );
})
As I'm wondering why console.log()
hasn't been provided as an answer, here it is.
Do:
console.log(arr);
And open the developper toolbar (F12 on most browsers) and go to the console tab. You should be able to see and expand your array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With