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

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training in India. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

    ReplyDelete