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

The Archive Base Latest Questions

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

I am confused the following loop causing an infinite loop in IE8 for (var

  • 0

I am confused the following loop causing an infinite loop in IE8

for (var i in theArray) {
            this.theArray.push(theArray[i]);
}

IE8 get caught in an infinite loop which I don’t understand why because this.theArray is a global array while theArray is a local variable.

If I had something like the following I would understand that an infinite loop would occurs:

for (var i in theArray) {
            theArray.push(theArray[i]);
}

This only happens in IE8. Does IE8 treat variables and scoping differently?

EDIT

Here is what I have within an object

this.theArray = new Array();

this.selection = function(theArray) {
    for (var i in theArray) {
        this.theArray.push(theArray[i]);
    }
}

EDIT

I found out that I am pass the global variable into the function as an argument. Duh! Why does this not work in IE8?

  • 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-03T02:55:39+00:00Added an answer on June 3, 2026 at 2:55 am

    First of all, never use for in loop on an array. It will iterate through the values as well as augmented properties.

    Then, this cannot be determined in your code. this might refer to the global object. Also, you might have missed using var in the local variable, thus making theArray point to the same global theArray you are appending to.

    var theArray = [1,2,3];
    
    function foo(){
        theArray = [4,5,6]; //missing var, theArray is the global theArray
        for (var i in theArray) {
            //you are pushing to the same array you are fetching from
            this.theArray.push(theArray[i]);
    
            //[4,5,6,4,5,6,4,5,6,.....]
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following loop translates the English word Welcome to a couple other languages. var
This may seem silly, but I'm a bit confused about the following code: public
I've always been confused about this one. Consider the following loops: int [] list
On the 2nd for-loop, I get the following error from gcc: error: expected unqualified-id
I am particularly confused by the following test case: public void TestMapping() { var
I'm new to OOP and I'm confused about this following line on chapter 6
This completely confused me for a while. I'm getting weird behaviour trying to loop
I am confused with the following result, I have a string like this:- string
I am little bit confused about following problem & their solutions: i have 2
I'm confused by the following code: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class

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.