Complex Arrays

We've touched on arrays before. Now we're going deeper.


var myArray = [1,2,3,4,5];

Heterogeneous Array

An array with mixed data types incl numbers, strings and booleans.

var myArray = [1,true,"tree",4,5,"sticks"];

Two Dimensional Array

Arrays within arrays. The simplest of these look kind of like a data table. Here's an example:

var my2DArray = [['Dog','Cat','Bird'],['Shnautzer','Siamese','Parrot'],['Doberman','Calico','Budgie']];

Dog Cat Bird
Shnautzer Siamese Parrot
Doberman Calico Budgie

We can also create multi-dimensional arrays, kind of like the inception of arrays, but I'm skipping that example.

Jagged Array

A jagged array is at least two dimensions, but unlike the above example doesn't have the same number of items in each subsequent array. For example:

var myJaggedArray = [["one","two",3],["four",5],[6,"seven",8,"nine"]];

one two 3
four 5
6 seven 8 nine