title: Declare a JSON array of Objects and add items dynamically
body: <p>This is stupid but i am missing something and could not reach the conclusion.
  I am trying to initialize a JSON Array and trying to add JSON Objects to it run time.
  For an example, I will be getting the list of repeated values from server something like below.</p>
  
  <pre><code>"employees":[
      {"firstName":"John", "lastName":"Doe"},
      {"firstName":"Anna", "lastName":"Smith"},
      {"firstName":"Peter", "lastName":"Jones"}
  ]
  </code></pre>
  
  <p>I have to create an array of object and fill these values in it.</p>
  
  <p>I am trying to initialize an array like </p>
  
  <pre><code>var myArr = []; 
  </code></pre>
  
  <p>and I want to add object with properties to it dynamically, something like below.</p>
  
  <pre><code>var myobj = {}
  
  for(int i=0;i&lt;length;i++)
  {
  myobj[i].name = serverrespOBJ.name;
  myobj[i].lastName= 'serverrespOBJ.lastname';
  myArr.push(myobj)
  }
  </code></pre>
  
  <p>I am getting the error that <strong>name</strong> can not be added to undefined, so i believe, my way of adding items to the object is incorrect.</p>
  
  <p>I am trying to find a good example but could not get it. Any help would be appreciated.</p>
  
  <p>Thanks</p>