简体   繁体   中英

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>

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/

您应在数组中引用“ q”,“ w”,“ e” ...个字符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM