Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7870699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:41:38+00:00 2026-06-03T01:41:38+00:00

I’m experiencing an odd behavior (maybe it isn’t odd at all but just me

  • 0

I’m experiencing an odd behavior (maybe it isn’t odd at all but just me not understanding why) with an javascript array containing some objects.

Since I’m no javascript pro, there might very well be clear explanation as to why this is happening, I just don’t know it.

I have javascript that is running in a document. It makes an array of objects similar to this:

var myArray = [{"Id":"guid1","Name":"name1"},{"Id":"guid2","Name":"name2"},...];

If I print out this array at the place it was created like JSON.stringify(myArray), I get what I was expecting:

[{"Id":"guid1","Name":"name1"},{"Id":"guid2","Name":"name2"},...]

However, if I try to access this array from a child document to this document (a document in a window opened by the first document) the array isn’t an array any more.
So doing 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 was expecting – I was expecting to get the same as I did in teh parent document.

Can anyone explain to me why this is happening and how to fix it so that the array is still an array when addressed from a child window/document?

PS. the objects aren’t added to the array as stated above, they are added like this:

function objTemp()
{
    this.Id = '';
    this.Name = '';
};

var myArray = [];

var obj = new ObjTemp();
obj.Id = 'guid1';
obj.Name = 'name1';

myArray[myArray.length] = obj;

If that makes any difference.

Any help would be much appreciated, both for fixing my problem but also for better understanding what is going on 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:41:39+00:00Added an answer on June 3, 2026 at 1:41 am

    The very last line might be causing the problem, have you tried replacing myArray[myArray.length] = obj; with myArray.push(obj);? Could be that, since you’re creating a new index explicitly, the Array is turned into an object… though I’m just guessing here. Could you add the code used by the child document that retrieves myArray ?

    Edit

    Ignore the above, since it won’t make any difference. Though, without wanting to boast, I was thinking along the right lines. My idea was that, by only using proprietary array methods, the interpreter would see that as clues as to the type of myArray. The thing is: myArray is an array, as far as the parent document is concerned, but since you’re passing the Array from one document to another, here’s what happens:

    An array is an object, complete with it’s own prototype and methods. By passing it to another document, you’re passing the entire Array object (value and prototype) as one object to the child document. In passing the variable between documents, you’re effectively creating a copy of the variable (the only time JavaScript copies the values of a var). Since an array is an object, all of its properties (and prototype methods/properties) are copied to a ‘nameless’ instance of the Object object. Something along the lines of var copy = new Object(toCopy.constructor(toCopy.valueOf())); is happening… the easiest way around this, IMO, is to stringency the array withing the parent context, because there, the interpreter knows it’s an array:

    //parent document
    function getTheArray(){ return JSON.stringify(myArray);}
    //child document:
    myArray = JSON.parse(parent.getTheArray());
    

    In this example, the var is stringified in the context that still treats myArray as a true JavaScript array, so the resulting string will be what you’d expect. In passing the JSON encoded string from one document to another, it will remain unchanged and therefore the JSON.parse() will give you an exact copy of the myArray variable.

    Note that this is just another wild stab in the dark, but I have given it a bit more thought, now. If I’m wrong about this, feel free to correct me… I’m always happy to learn. If this turns out to be true, let me know, too, as this will undoubtedly prove a pitfall for me sooner or later

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.