Working with arrays:
- arrays store several pieces of data in a single element
- array declaration e.g. var myArr = [“some text”, 23, “hello”];
- you can nest arrays within other arrays e.g. var ages = [[“Jon”, 28], [“Bob”, 43]];
- access array elements using zero-based indexing, e.g. myArr is “some text”
- array entries are mutable, unlike strings
- multidimensional arrays also use indexes to access elements e.g. ages is 28
- append data to the end of an array using the push() function e.g. myArr.push(“world”);
- remove the last value on an array using the pop() function e.g. myArr.pop() would undo the above push. Further, if we’d said var removed = myArr.pop(), removed would store the value “world”.
- .shift() removes the first element, rather than the last
- .unshift() adds an element to the start of an array
Short one for today. Next, functions!