I just started learning JavaScript.
I'm trying to display a one-dimensional array of numbers from 0 to 9 using JavaScript.
Output : nothing is displayed on the screen.
Can you let me know where I went wrong.Thanks in advance!
<html>
<body>
<script>
var num = new array();
for(var i=0;i<10;i++)
num[i]=i;
for(var i=0;i<10;i++)
document.write(num[i]+"<br>");
</script>
</body>
</html>
Mistake is 1st line of the script. array
should be Array
change line
var num = new array()
to
var num = new Array()
array needs an upper case A.
Fix declaration to var num = [];
Debug your's code in Chrome console (F12)
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.