Array of GameObjects - JS

Hi, i have a question here about Arrays.

I have two variables

var itemsSlots :  GameObject[];

var itemsListArray  :   Array;

there are three prefab items in itemsSlot which i added in the Inspector.

When i am calling this function

function SomeFunction() {
	for(var i = 0; i < itemsSlots.Length; i++) {
	    print("for loop       = " + itemsSlots*);		*
  •  itemsListArray.Add(i);*
  • } *
    what exactly am i storing in itemsListArray.Add(i) ? Is it only number of items in itemsSlots
    in this case 3 ? Therefore i can refer to those objects only as to integers.
    And if yes how can i store and retrieve the actual object originally
    added in the Inspector.

What are you planning on doing with the game objects? If you just want to be able to access them you really don’t need the itemsListArray at all. You can just reference the itemsSlots game objects directly.

The answer to your question is that you will have 1, 2, 3 in your itemsListArray. This seems kind of odd that you would need an array full of integers. Those integers don’t really help you get to the game objects.

Maybe if you explain what you are trying to do we can help you better.