I experience strange behavior (maybe this is not strange, but I just don’t understand why) with a javascript array containing some objects.
Since I am not a javascript developer, there may well be a clear explanation of why this is happening, I just don't know this.
I have javascript that works in a document. It makes an array of objects look like this:
var myArray = [{"Id":"guid1","Name":"name1"},{"Id":"guid2","Name":"name2"},...];
If I print this array in the place where it was created as JSON.stringify (myArray), I get what I expected:
[{"Id":"guid1","Name":"name1"},{"Id":"guid2","Name":"name2"},...]
However, if I try to access this array from a child document into this document (the document in the window opened by the first document), the array is no longer an array. Thus, executing JSON.stringify (parent.opener.myArray) in the child document will result in the following:
{"0":{"Id":"guid1","Name":"name1"},"1":{"Id":"guid2","Name":"name2"},...}
And this was not what I expected - I expected to get the same as in the parent document.
Can someone explain to me why this is happening and how to fix it so that the array is still an array when accessed from a child window / document?
PS. objects are not added to the array, as indicated above, they are added as follows:
function objTemp() { this.Id = ''; this.Name = ''; }; var myArray = []; var obj = new ObjTemp(); obj.Id = 'guid1'; obj.Name = 'name1'; myArray[myArray.length] = obj;
If that matters.
Any help would be greatly appreciated both for fixing my problem and for a better understanding of what is happening :)