- Home /
Question by
gochnauer · Jun 09, 2013 at 09:50 PM ·
arraysmultidimensional array
Access the name of a sub array in a multidimensional array
I have a multidimensional array like in the following example. I need to be able to access the name of a sub array in the multidimensional array as a string.
var hats = [big, small, flat];
var hair = [blond, brown, black];
var eyes = [blue, green];
var items= [hats, hair, eyes];
for (var i = 0; i < items[i].Length -1; i++){
print(items[i]); //get the array name as a string here
}
Comment
Answer by gochnauer · Jun 10, 2013 at 02:40 PM
Ok so because my arrays won't be adding or removing items I ended up creating another array with the items as strings. It's annoying but I see no way around it.
var hats = [big, small, flat];
var hair = [blond, brown, black];
var eyes = [blue, green];
var items= [hats, hair, eyes];
var itemNames = ["hats","hair","eyes"]
for (var i = 0; i < items[i].Length -1; i++){
print(itemsName[i]);
}