Add properties to array of objects - Javascript Object

Javascript examples for Object:Object Property

Description

Add properties to array of objects

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 v a2 s.  co m
var array = [{'content1': 'abc', 'id1':'100'},{'content2': 'xyz', 'id2':'200'}];
array[0].name = 'foo';
array[1].name = 'bar';
for (var i = 0; i < array.length; i++)
    console.log(array[i].name);
    }

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

Related Tutorials