0

I need to do something like this:

Section 1, Chapter 1 title is "Dogs"

Section 1, Chapter 2 title is "Cats"

Section 2, Chapter 1 title is: "Goldfish"

I want to be able to write it something like this, with arrays:

section[0].chapter[0] = "Dogs";
section[0].chapter[1] = "Cats";
section[1].chapter[0] = "Goldfish";
sinemetu1
  • 1,726
  • 1
  • 13
  • 24
Orb Hitter
  • 317
  • 1
  • 4
  • 9

2 Answers2

1

This other post on stackoverflow has some answeres on how to create 2-dimensional arrays. How can I create a two dimensional array in JavaScript?

Or you could use a "class", though this may be needlessly complex...

function Section ()
{
  this.Chapters = new Array( 10 );
}

function CreateSection ()
{
  var sections = new Array ( 10 );

  sections[0] = new Section ();
  sections[0].Chapters[0] = "dogs";

  alert (  sections[0].Chapters[0] );
}
Community
  • 1
  • 1
WonderfulDay
  • 148
  • 1
  • 1
  • 4
  • Thanks! The multidimensional array is what I'm looking for... I saw an example on it before but it didn't seem to work, the approach was a little different. – Orb Hitter Mar 20 '12 at 21:52
0

do you mean like a Multi Dimentional Array?

How can I create a two dimensional array in JavaScript?

Community
  • 1
  • 1
Mike Sav
  • 14,805
  • 31
  • 98
  • 143