Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to a range within a multidimensional array

Status
Not open for further replies.

tektippee

IS-IT--Management
Jun 15, 2008
6
US
My javascript array has values for "chapter", "paragraph",
"sentence", and the text of this sentence.
It looks like this:

book = [
[1, 1, 1, "Hi Mary."],
[1, 1, 2, "Today's Tuesday"],
[1, 1, 3, "We came back from fishing."],
...
...
[4, 26, 9, "We then took a nap."],
[4, 26, 10, "That was Tuesday"],
[4, 27, 1, "On Wednesday it was raining."],
...
...
[8, 84, 6, "Then he waved goodbye."]
];

How do I point into this array? That is, how do I
get to and sequentially process within this array?
The only parameters I get are the 1st and last chapter
numbers, i.e., the first element in the first and last
entries (inclusive) of the range.

E.g.
How would I process from [4, , , ] through [6, , , ]?
Or, e.g.,
all of chapter 4's records?

Thank you.
 
Hi

I not really understand what you want. For example this will output all sentences in the chapter interval 4-6 :
JavaScript:
[b]for[/b] [teal]([/teal][b]var[/b] i[teal]=[/teal][purple]0[/purple][teal],[/teal]l[teal]=[/teal]book[teal].[/teal]length[teal];[/teal]i[teal]<[/teal]l[teal];[/teal]i[teal]++)[/teal]
  [b]if[/b] [teal]([/teal]book[teal][[/teal]i[teal]][[/teal][purple]0[/purple][teal]]>=[/teal][purple]4[/purple] [teal]&&[/teal] book[teal][[/teal]i[teal]][[/teal][purple]0[/purple][teal]]<=[/teal][purple]6[/purple][teal])[/teal] document[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal]book[teal][[/teal]i[teal]][[/teal][purple]3[/purple][teal]])[/teal]

Feherke.
 
You're hardcoding values which should be read as indices of arrays.

book = [
[
["Hi Mary.","Today's Tuesday","We came back from fishing"],
["This is chapter 1, paragraph 2"]
],

....

[
["We took a nap","That was on Thursday"],
["new paragraph","second sentence"]

]
];



chapter 4 can be found at
book[3]
chapter 6, paragraph 3 is:
book[5][2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top