Mid Level Data Types
Slightly more advanced than the simple types, I consider these to be "mid-level" (this isn't a standard terminology, though, just what I call them!).
Arrays
An Array could be called a "list" in some other languages. It consists of a very simple series of things between square brackets ([]
). You can put anything inside of arrays, and you can even mix and match different data types inside of it.
Arrays are "accessed" through their numerical index, in other words, their position in the array. Using the above examples:
Notice that the first element is at index 0
, not one. This is what we call "zero-based", so it really does start at 0, not 1.
Learn more about arrays in Working with Arrays.
Objects
An object is a series of key and value pairs put together between {}
, as shown in the array example. Contrarily to arrays, the "index" (which we called the "key") has an actual text name. Objects cannot have multiple keys of the same name.
Note that object key/value pairs are defined with a semicolon (:
) not an equal sign. Each key/value pair must be separated by a comma (,
). The last value should not have a comma after it. Those details are important!
Theoretically, almost everything except the simple value types are objects. Arrays, classes, functions, maps and sets... all objects. While that's something to keep in mind for later, for now I'll refer to "objects" specifically as "a series of key/value pairs surrounded by
{}
.
Last updated