SitePoint Sponsor

User Tag List

Results 1 to 20 of 20

Threaded View

  1. #1
    SitePoint Member molot0v's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript object arrays

    Hi all

    I've got a question:

    Can I make an object array in Javascript?

    ie.
    Code:
    function foo()
    {
      var fooNumber=10;
      fooFunction;
    }
    
    function fooFunction()
    {
      return fooNumber;
    }
    
    function makeFoos()
    {
      var someArray[100];
      var counter=0;
      for ( i=0; i<=100; i++)
      {
    
    // changes as of Aug 27:
        someArray[i] = new foo();
    
    // the offending line!
        alert(someArray[eval(i)].fooFunction());
    
      }
      
    }
    In my script (which is fairly similar to the above), when I try to refer to one of my foo's, ie.
    alert(someArray[10].fooFunction());
    Mozilla spits out the error:
    "Error: someArray[10] has no properties"

    Any ideas? Am I going about this the wrong way?

    Cheers
    Chris
    Last edited by molot0v; Aug 27, 2003 at 06:45.


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
  •