two dimensional arrays

M

Max

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
 
T

Thomas 'PointedEars' Lahn

Max said:
I would like to create a two dimensional array.

No, you would like to create an array of objects.
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:

// define the object prototype
function PlaylistItem(sArtist, 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),
...);
var newVar = myArray[0].Artist

var newVar = myArray[0].artist;


HTH

PointedEars
 
D

Douglas Crockford

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

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}];

http://www.JSON.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top