iteratively add object to an array of objects in Javascript - Javascript Array Operation

Javascript examples for Array Operation:Array of Object

Description

iteratively add object to an array of objects in Javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {// w w w. j  a  va2s.c  o m
var series = {
    data: []
};
for (var i=0; i<10; i++) {
    var datatemp={};
    datatemp.y = i;
    datatemp.name = "nameValue "+i;
    series.data.push(datatemp);
}
for (var i=0; i<10; i++) {
    console.log(series.data[i].y);
        console.log(series.data[i].name);
}
    });

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

Related Tutorials