Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 3: Finishing the Game Loop

Info: Arrays

You don’t have access to this lesson

Please register or sign in to access the course content.

Arrays allow you to capture a list of objects of the same type, and find individual objects using a number, called an index

The index always starts at 0. You can call this the “zeroth element” of the array. 

To get a specific element, use [ ] square brackets after the array variable name, with the element number inside. If you use an index that isn’t in the array, you will get undefined

Using .length will give you the total number of elements in the array. 

  • If the length of the array is 1, the index of that one element will be [0]
  • If the length of the array is 0, there are no elements in the array. Trying any index will give you undefined.
  • If the length of the array is 7, the index of the last element will be [6]
  • In general, you can find the last element using [myArrayName.length - 1]

You can read more about arrays here: