Generate an array of dictionaries with a For loop and output its value - Javascript Array Operation

Javascript examples for Array Operation:Associative Array

Description

Generate an array of dictionaries with a For loop and output its value

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <p id="demo"></p> 
      <script>
var arr=[];//from ww w . j  a va  2  s  .  c  o m
var i;
var text="";
for(i=0;i<10;i++){
   arr.push({firstName : "John"})
}
for(i=0;i<10;i++){
   text=text+arr[i].firstName+'<br />'
}
document.getElementById("demo").innerHTML = text;

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

Related Tutorials