- Home /
Add a new Array List to an Array List.
I know this is possible with ordinary arrays. I use them like this for the most part
myArray.push("Lesson:",Array("Name","Page","Paragraph"));
and I access them as so:
myArray[0]
gets me "Lesson" and myArray[0][0]
thru [0][2]
gets me "Name, Page, and Paragraph"
How would this be possible in an ArrayList. I am using Javascript
Answer by Jessy · Jan 13, 2011 at 11:36 PM
I've never heard of a type of array that functions like you explained. However, I don't know "web JavaScript", so maybe something like that exists therein. A jagged array stores arrays, so myArray[0] should return your array of strings, not a string. If you have an example to the contrary, please show that code and I'll see if I can offer something that matches it better.
In the meantime, I'm going to recommend a List of structs. You could have a List of Lists, but then you wouldn't have a "title" for each of the lists, like it seems that you want.
class BoringSchoolwork extends System.ValueType { var title : String; var contents : List.<String>;
function BoringSchoolwork (title : String, contents : List.<String>) {
this.title = title;
this.contents = contents;
}
} var myList : List.<BoringSchoolwork> = List.<BoringSchoolwork>();
myList.Add(BoringSchoolwork("Lesson:", List.<String>(["Name","Page","Paragraph"])) );
Javascript does support structs: http://unity3d.com/support/documentation/$$anonymous$$anual/$$anonymous$$onoUpgradeDetails.html
Ohhh, that PAGE!!! Remember that time when JavaScript looked cleaner than C#, in Unity? ;-)
Your answer
Follow this Question
Related Questions
Editor utility for handling nested prefabs.. 4 Answers
Nested for-loop freezing Unity 1 Answer
How to display my castle name at runtime 3 Answers
Is it ok to use nested classes, to cache and access components? 1 Answer
Identifier Expected Error ArrayList -1 Answers