SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot maileen's Avatar
    Join Date
    Apr 2006
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question use object store in array

    Hi,

    i have defined a class jARColumn with a property name.
    i have created 3 objects of this jARColumn class as following:
    Code:
    var col1 = new jARColumn("column name 1");
    var col2 = new jARColumn("column name 2");
    var col3 = new jARColumn("column name 3");
    i store those 3 column into my array as following:
    Code:
    var myArray = new Array();
    myArray.push(col1);
    myArray.push(col2);
    myArray.push(col3);
    Now i would like to display the name of my col2 for example:
    Code:
    alert("Column Name : "+jARColumn(myArray[1]).name);
    here is the problem... it does not display the column name but an error :-(
    it tells me that jARColumn(myArray[1]) is undefined

    any idea ? i guess my casting is wrong but i do not see where :-(
    thx.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    As each array item is already an instantiation of jARColumn, I presume that you should be able to access the property name without calling jARColumn again.

    Code javascript:
    alert("Column Name : "+myArray[1].name);

    Here is some sample test code

    Code javascript:
    function jARColumn (name) {
    	this.name = name;
    }
    var col1 = new jARColumn("column name 1");
    var col2 = new jARColumn("column name 2");
    var col3 = new jARColumn("column name 3");
     
    var myArray = new Array();
    myArray.push(col1);
    myArray.push(col2);
    myArray.push(col3);
     
    alert("Column Name : " + myArray[1].name);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot maileen's Avatar
    Join Date
    Apr 2006
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot, it works well.
    my IDE made me confused :-(


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
  •