Wednesday, September 28, 2011

JavaScript: Create simple array using loop

Code:
<script type="text/javascript">
// same with --> var value = [];
var value = new Array(8); 

for(var i=0; i<=8; i++) {
 value[i] = i;
}

// check output 
console.log(value);

// print output
for(i=0; i<=8; i++) { 
   document.write(value[i] + ", "); 
}
</script>
Output:
0, 1, 2, 3, 4, 5, 6, 7, 8
Refer: http://www.hunlock.com/blogs/Mastering_Javascript_Arrays

6 comments:

  1. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
    python Training institute in Pune
    python Training institute in Chennai
    python Training institute in Bangalore

    ReplyDelete