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";
1
  • 4
    Yes. What trouble are you having? Commented Mar 20, 2012 at 20:54

2 Answers 2

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] );
}
Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

do you mean like a Multi Dimentional Array?

How can I create a two dimensional array in JavaScript?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.