objects in arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philip WATTS

    objects in arrays

    " " indicates code.

    I have created a javascript object by use of a function.

    object function
    "function myObject(attrib ute1, attribute2,etc) "
    {
    "this.attribute 1=attribute1"
    "this.attribute 2=attribute2"
    etc
    }
    I wish to put the object I create into an array, so I create the array

    "myObjectArray= new Array()"

    Then I say that I wish to fill the aray with objects

    "myObjectArray= new(myObject)"

    Then I create the instances

    "myObjectAr ray[0]=new myObject(attrib ute1,attribute2 ,etc)"
    "myObjectAr ray[1]=new myObject(attrib ute1,attribute2 ,etc)"

    This all seems to work fine until I try and establish how many objects I
    have by looking at the length of my myObjectArray.

    "myObjectArray. length" returns as undefined.

    What am I doing wrong?

    Many thanks
    Phil


  • Lee

    #2
    Re: objects in arrays

    Philip WATTS said:[color=blue]
    >
    >" " indicates code.
    >
    >I have created a javascript object by use of a function.
    >
    >object function
    >"function myObject(attrib ute1, attribute2,etc) "
    >{
    >"this.attribut e1=attribute1"
    >"this.attribut e2=attribute2"
    >etc
    >}
    >I wish to put the object I create into an array, so I create the array
    >
    >"myObjectArray =new Array()"
    >
    >Then I say that I wish to fill the aray with objects
    >
    >"myObjectArray =new(myObject)"[/color]

    That's your problem. Leave that line out and it should work.
    After that line, myObjectArray is no longer an array.
    You don't have to say what you're going to put into an array,
    and there is no way to do so.

    Comment

    Working...