Array working in IE, not in Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Array working in IE, not in Firefox

    I have an array of values, variable length. I'm writing a bookmarklet to make a task simpler and I'm having an issue with the way Firefox is reading the array. Internet Explorer (8) works fine.

    Basically, let's say my first array element is this:

    myArray[0] = "value1",

    Calling up the value should look like this:

    myArray[0];

    In IE that would return "value1". In Firefox it's returning the number 0. This is causing the next line to error, since it's expecting a value. I tried doing:

    alert(myArray):

    And it returns this in Firefox:

    0,1,2,3,4,5,6,7 ,8,9,10,11

    IE returns the actual values. Is there something I'm missing here? I need the code to work in both, but I just can't figure it out.
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #2
    Ugh...nevermind with this. I HAD missed something. The loop that I was assigning my array values in worked differently in Firefox that in IE, so I had to change it for Firefox and I forgot to change the value that actually assigned to the array. It works now. Sorry.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      when it alerts that ... then the array is in fact:

      Code:
      myArray = [0,1,2,3,4,5,6,7,8,9,10,11];
      so we would need to see some code where you assign the values to the array ...

      PS: ok ... you did find it out already :)

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        Originally posted by gits
        when it alerts that ... then the array is in fact:

        Code:
        myArray = [0,1,2,3,4,5,6,7,8,9,10,11];
        so we would need to see some code where you assign the values to the array ...

        PS: ok ... you did find it out already :)
        Yeah, I was doing a foreach loop through a tag's child elements:

        for(var i in array)

        In IE the value of i would be the element's ID value, in firefox it just returns the number, so I had to do this:

        for(var i in array)
        var value = array[i].id;

        And it worked in both.

        Comment

        Working...