Use object literal as array element - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Use object literal as array element

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   ww  w  . j a  va2  s.  c om*/
var site = { name: 'stackoverflow' };
var users = [ { name: 'hi'} ];

for (var i = 0; i < users.length; i++) {
    users[i].site = site;
}

site.users = users;

console.log(site.users);

    }

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

Related Tutorials