SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Toronto, ON, Canada
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Arrays and Objects

    I am dabbling with objects and have successfully created an object with various properties, one of which is an Array, and all is fine. the Question I have is can I make an Array of objects? I have the following object:

    dataSeries.Type = value
    dataSeries.Name = value
    dataSeries.dataPoints[n] = Array of values
    dataSeries.color = value

    What I would like to do is have an Array of multiple objects supposedly like:

    dataSeries[0].Type = value
    dataSeries[1].Name = value
    dataSeries[2].dataPoints[n] = Array of values
    dataSeries[3].color = value

    Is this possible?

    Thanks,

    Rob.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rob,

    Code:
    <html>
    <head>
    <script type='text/javascript'>
    
    var Series = new Array();
    
    window.onload = function() {
      var i;
    
      Series[0] = new DataSeries(1,'fib', 'red', [3, 5, 8]);
      Series[1] = new DataSeries(2, 'sq', 'white', [4, 9, 16]);
      Series[2] = new DataSeries(3, 'pr', 'blue', [3, 5, 7]);
      
      for (i = 0; i < Series.length; ++i) {
        Series[i].show();
      }
    }
    
    function DataSeries(type, name, color, points)
    {
      // Properties
      this.type = type;
      this.name = name;
      this.color = color;
      this.points = points;
      // Methods
      this.show = function()
      {
        alert(
          'DataSeries\n' +
          'type: ' + this.type + '\n' +
          'name: ' + this.name + '\n' +
          'color: ' + this.color + '\n' +
          'points: ' + this.points);
      }
    } // end DataSeries
    
    </script>
    </head>
    <body>
    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Toronto, ON, Canada
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I think that might be perfect.

    Rob.


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
  •