how to play with array of array

Hi, I’m trying to make a inventory for my game, there have 4 bags each bag has 20 slot inside.
now I need a array called bagList() that allow to store slotList1(), slotList2, slotList3(), slotList4(). and each slotList array has different item inside.

I have been created them like this:

static var bagList= new Array();
static var slotList1=new Array();
static var slotList2=new Array();
static var slotList3=new Array();
static var slotList4=new Array();

//add bags
bagList[0]=(slotList1);
bagList[1]=(slotList2);
bagList[2]=(slotList3);
bagList[3]=(slotList4);

//add items
slotList1[2]=("Assets/Items/testing");
slotList1[15]=("Assets/Items/testing");
slotList3[3]=("Assets/Items/testing");
slotList2[8]=("Assets/Items/testing");
slotList4[11]=("Assets/Items/testing");

that’s a good start everything is work.

but I got many questions when I’m trying to processing with my arrays.

1.how to get the slotList1.length by through bagList? (eg:bagList[1].length)

2.how to get the first item that inside slotList1 by through bagList? (eg:bagList[1][0])

3.how to add item to slotList1 by through bagList? (eg:bagList[1][0][2]=“apple”)

I know how to get/add items for single array (eg:slotList1[2]=“apple”)
but in my game situation that must take bagList first then slotList.
can anyone help me please?

If you can bring some example that would be perfect! (JavaScript please)

I recommend creating a simple class for your bags:

class Bag {
         var slotList : String[] = new String[20];
    }

Then you just create an array of this class:

var bags : Bag[] = new Bag[4];

Now you can access your bags and their slotLists like this:

bags[2].slotList[14] = "Apple";
var anySlotContent : String = bags[1].slotList[7];
var bagNumber : int = bags.Length;
var slotListSize : int = bags[0].slotList.Length;

You didn’t mention what kind of Type the SlotLists actually store, I just used string for my example but with GameObjects or custom Item classes it’s the same.
Note that if you create a custom class as a seperate script, you have to add [System.Serializable].