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.
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
I have to create an array of object and fill these values in it.
I am trying to initialize an array like
var myArr = [];
and I want to add object with properties to it dynamically, something like below.
var myobj = {}
for(int i=0;i<length;i++)
{
myobj[i].name = serverrespOBJ.name;
myobj[i].lastName= 'serverrespOBJ.lastname';
myArr.push(myobj)
}
I am getting the error that name can not be added to undefined, so i believe, my way of adding items to the object is incorrect.
I am trying to find a good example but could not get it. Any help would be appreciated.
Thanks