two dimensional arrays

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

    #1

    two dimensional arrays

    I would like to create a two dimensional array.
    I would like an array where I can store 4 variables like (Artist, Track,
    Album, Time) like per Element so I can access it later by element and
    variable like:

    var newVar = myArray[0].Artist

    Would anybody know if it is possible and give me an example for the code.
    Thanks

    Max



  • Thomas 'PointedEars' Lahn

    #2
    Re: two dimensional arrays

    Max wrote:
    [color=blue]
    > I would like to create a two dimensional array.[/color]

    No, you would like to create an array of objects.
    [color=blue]
    > I would like an array where I can store 4 variables like (Artist, Track,
    > Album, Time) like per Element so I can access it later by element and
    > variable like:[/color]

    // define the object prototype
    function PlaylistItem(sA rtist, sAlbum, sTrack, nTime)
    {
    this.artist = sArtist || "";
    this.album = sAlbum || "";
    this.track = sTrack || "";
    this.time = nTime || -1;
    }

    // create array of PlaylistItem objects
    var myArray = new Array(
    new PlaylistItem(
    "The Corrs",
    "Unplugged" ,
    "Lough Erin Shore",
    4 + 25/60),
    ...);
    [color=blue]
    > var newVar = myArray[0].Artist[/color]

    var newVar = myArray[0].artist;


    HTH

    PointedEars

    Comment

    • Albert Wagner

      #3
      Re: two dimensional arrays

      On Fri, 7 Nov 2003 19:02:47 -0000
      "Max" <gallfam@ntlwor ld.com> wrote:
      <snip>[color=blue]
      > ... so I can access it later...[/color]
      <snip>

      Later in the same script or later in the sense of persistence across
      sessions?

      --
      Life is an offensive, directed against the repetitious mechanism of the
      Universe.
      --Alfred North Whitehead (1861-1947)

      Comment

      • Douglas Crockford

        #4
        Re: two dimensional arrays

        > I would like to create a two dimensional array.[color=blue]
        > I would like an array where I can store 4 variables like (Artist, Track,
        > Album, Time) like per Element so I can access it later by element and
        > variable like:
        >
        > var newVar = myArray[0].Artist[/color]

        var myArray = [
        {Artist: "Gut", Track: "Do the Gorilla", Album: "Songs in the Key of E",
        Time: 3.5},
        {Artist: "Gut", Track: "The Vision", Album: "Songs in the Key of E", Time:
        3.65}];





        Comment

        Working...