Ronk
Ronk

Reputation: 225

Displaying array content in alert box

This DOES WORK in other scripts I have written, but not here. Why? Other scripts I have written have been able to display the entire array, and were able to display 1-2-3 levels deep. ie Original[0] / Original[0][0] Am I missing something VERY simple?

Winning answer HERE: How can I create a two dimensional array in JavaScript? Works fine?

<html>
<head>

<script>
Original = [
[1,2,3,4,5,6,7,8,9,0],
[0,9,8,7,6,5,4,3,2,1],
[q,w,e,r,t,y,u,i,o,p],
[a,b,c,d,e,f,g,h,i,j],
];

function TestFunction(){
alert(Original);
}


</script>
</head>
<body>
<button onClick = TestFunction()>Test</button>
</body>
</html>

Upvotes: 0

Views: 180

Answers (2)

Gergely Laborci
Gergely Laborci

Reputation: 147

You should quote your "q","w","e" ... characters in the array.

Upvotes: 2

Richard Hamilton
Richard Hamilton

Reputation: 26444

The problem was that you have a bunch of undeclared variables. In an array, strings must be enclosed in quotation marks.

Original = [
[1,2,3,4,5,6,7,8,9,0],
[0,9,8,7,6,5,4,3,2,1],
['q','w','e','r','t','y','u','i','o','p'],
['a','b','c','d','e','f','g','h','i','j'],
];

Here is an updated fiddle

http://jsfiddle.net/4fmtqou2/

Upvotes: 3

Related Questions