BasicDataStructures

When using JavaScript, the basic data structures do not behave as you expect. There are other data structures you can use, but they have syntactic nuances. You can read the MSDN page about these data structures but the basics are collected here.

Static Typing
Unity uses Javascript's data typing features to help it figure out the types of the variables you use. You are often not required to use the static typing features because the Unity engine will try to figure out what type you mean. When you use dynamic typing, sometimes the error messages are less clear than when you use static typing - so if you get an incomprehensible error message, try adding type definitions to your variables, especially loop variables - eg.

Variable Creation/Assignment

 * Dynamic:
 * Static:

The two dynamic examples are more-or-less identical in browsers. However, Unity always interprets  as being assignment to an already existing variable, and   as creating a variable in the current scope. This can mean that you're accidentally creating  if you use the   prefix when you mean to assign to an existing variable. Inspector Tip: Creating "blank" variables in the global namespace (outside of any function) using the  syntax is necessary for it to show up in the Inspector.

Hash Tables
Hash tables are an important exception to all the suggestions above. You cannot initialize an empty hash-table using. You must use  to initialize a hash table.

Significant functions/methods of the hash table:
 * Count : An integer number of elements in the hash table.
 * Keys : A collection (list-like data structure) of the keys in the hash table.
 * Contains(aKey) : Is aKey a key in the hash table?
 * Remove(aKey) : Removes a key/value pair.
 * Add(aKey, aValue) : Equivalent to

ArrayLists
You might be tempted to use  for your arrays. While this is understandable, the Array implementation has some significant limits, notably not supporting the  method. The ArrayList has many of the convenience methods one might want. Warnings:
 * You cannot create a null ArrayList using  and subsequently access that ArrayList's members without first creating it. Workaround: in your   function, do
 * You cannot access the ArrayList constructor -  doesn't work. Workaround: You must create the ArrayList and subsequently populate it.

Significant functions/methods of the array list:
 * Count : An integer number of elements in the array. Use this instead of . e.g.
 * Contains(anObject) : Is aMember an element in the hash table? e.g..
 * Remove(aMember) : Removes aMember. Does not raise an error if aMember doesn't exist in the array.
 * Add(anObject) : Equivalent to  except that   works.