SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Can a JS array be an associative + ordered array at the same time in older browsers?

    I know that JS arrays (objects, whatever) can be used as both an associative array and an ordered array at the same time. I have tested the following script in IE6, FF1+, and Opera and it works fine.

    What I don't know is how this works in older browsers / versions of javascript. Does anyone have any input on this?

    Code:
    <script>
    var foo = [];
    
    //-- add associative elements
    foo['cat'] = 'meow';
    foo['dog'] = 'woof';
    
    //-- add ordered elements
    foo.push('beer');
    foo.push('wine');
    
    //-- access associative elements
    document.write(foo['cat']+'<br>\n');
    document.write(foo['dog']+'<br>\n');
    
    //-- iterate over ordered elements
    for (var x=0;x<foo.length;x++) {
     document.write(foo[x]+'<br>\n');
    }
    </script>
    Last edited by jim_spath; Mar 18, 2005 at 12:11.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •