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 8601711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:54:23+00:00 2026-06-12T01:54:23+00:00

I was going to write this to be long and complicated, but i figured

  • 0

I was going to write this to be long and complicated, but i figured to go to the straight forward approach.

I have a loop that creates an array of elements where the variable Url. The array looks like this:

 x = [url,function(){...},function(){...}];

and then into an arrayList:

 arrayList = [x1,x2,x3,x4,x5];

I figure that makes sense so far. It stores in the arrayList object, 1 var and 2 functions.

Here is the kicker.

When i iterate through arrayList, url is all the same, the last reference to url in the forloop that created the arraylist.

My attempt to solve this was, doing a .toString() on the variable to store the contents of it in the array, instead of the variable name itself. that didnt work 🙁

What would i do to resolve this? im stumped 🙁

Edit: I want to show what the loop looks like because 1 of the answers was about the array inaccurately referencing it

Edit2: The url which is causing issues, is the inner url, in displayFile below. It seems those are all pointing to the same reference, which is a nono. How would i go about changing those? Would i have to pass it in as a parameter???

var newArray = new Array();
for(var i=0;i<fileUrls.length;++i) {
   var url = fileUrls[i];
   var x = [];//new Array();
   x = [url,
    function(){
       displayFile(url, 'image', null, ft_id, null, null, null, null, !MA.isiOS());
    }, 
    function(e){
    if(DEBUG) console.log('Error creating gallery thumbnail');
    alert('There was a problem creating a thumbnail');
    MA.hideMessage();
    }
];
newArray.push(x);
}
  • 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-12T01:54:25+00:00Added an answer on June 12, 2026 at 1:54 am

    What I think that you have is rather:

    arrayList = [x,x,x,x,x];
    

    I.e. an array that contains a number of references to the same object. If that is the case, then when you look at the url property in the different items, you are looking at the same property all the time, because it’s the same item over and over.

    That would be the result of reusing the array to populate the arrayList array, for example:

    var x = [];
    var arrayList = [];
    for (int i = 0; i < 5; i++) {
      x[0] = 'url ' + i;
      x[1] = function(){};
      x[2] = function(){};
      arrayList.push(x);
    }
    

    The solution would be to create a new array in each iteration:

    var arrayList = [];
    for (int i = 0; i < 5; i++) {
      var x = [];
      x[0] = 'url ' + i;
      x[1] = function(){};
      x[2] = function(){};
      arrayList.push(x);
    }
    

    Edit:

    To get the url variable used in the displayFile call to be specific for each iteration, you need a closure to capture the value:

    var newArray = new Array();
    for(var i=0;i<fileUrls.length;++i) {
      var url = fileUrls[i];
      var x = [];//new Array();
    
      var f;
      (function(url){
        f = function(){
          displayFile(url, 'image', null, ft_id, null, null, null, null, !MA.isiOS());
        };
      })(url);
    
      x = [url, f , 
        function(e){
          if(DEBUG) console.log('Error creating gallery thumbnail');
          alert('There was a problem creating a thumbnail');
          MA.hideMessage();
        }
      ];
      newArray.push(x);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I write to long text for example this: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa The text is going
Im new on this project and am going to write, what i thought was
I am going to write an app for google services, but I stuck at
I'm going to write a CMS, but right now I'm writing down all my
This question is going to be rather long, so I apologize preemptively. In Python
I've decided that I'm going to write an API for my music site. Something
I'd like to write shortcut for this code for example , i'm going to
Suppose that this file is 2 and 1/2 blocks long, with block size of
I'm 100% sure this is going to be one of those newbie questions, but
this may be a stupid question or a typo but I'm going to ask

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.