Use parameter to define field name - Javascript Object

Javascript examples for Object:Object Property

Description

Use parameter to define field name

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(){//from w  w  w  . j  a  va2  s  .c o m
var n = 10
var collections = [];
for(var i = 0; i < 10; i++){
  var json1 = {};
  var row = [];
  json1['color'] = '#000000';
  json1['y'+i+'axis'] = {from: 1234};
  row.push(json1);
  collections.push(row);
}
console.log(collections);
    }

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

Related Tutorials