Notes on Arrays


let myArray=["this", "that", "and the other thing"];

push() and pop() add and remove from the end.

push() and pop() make an array like a stack

Last in, first out

Think of a stack of dishes

A "LIFO queue"


unshift() and shift()

LIFO, FILO, FIFO, or LILO?

Is waiting on line . . .

LIFO, FILO, FIFO, or LILO?



















unshift() and shift() are like push() and pop() except looking at the array in the other direction
To use an array as FILO queue (like standing in line):
     Use unshift(x) to add and pop() to remove
     or use push(x) to add and shift() to remove

A stack is great for checking if parens are balanced!

More generally: good for checking for correct syntax


Consider myArray.forEach(myFunc)

What does the type of myFunc need to be?

So a let can have type number, function, . . .

Multidimensional arrays are arrays of arrays

If you have an array of 2 arrays (a 2x2 array), each with 2 numbers as elements, how many numbers in the whole thing?

2x2x2?

2x2x2x2?

10-D array, 2 on each dimension?

JavaScript: lengths may be all different

Example:

let a=[4, [3, 7], [3, 6, [[[[9, 5, 2, []]]]]];

How are arrays stored in memory?

C vs. JavaScript