Array for loop, assign value and access value - Javascript Array Operation

Javascript examples for Array Operation:Array Index

Description

Array for loop, assign value and access value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script>
var numbers = [];/*from   w  w w  .j av a 2s. c om*/
var sum = 0;
for (var i = 0; i <= 100; i = i + 3) {
    numbers[(i-3)/3] = i;
}
for (var index = 0; index <  numbers.length; index++) {
    document.write("<br/>" + numbers[index]);
    sum = sum + numbers[index];
}
document.write("<br/>sum = " + sum);

      </script>  
   </body>
</html>

Related Tutorials