Recap

Grade 7, page 14 of 14. A one-minute read.

  • An array is an ordered list of values, written with square brackets: ["a", "b", "c"].
  • Items are accessed by index, starting at 0. The last item is at length - 1 (or use .at(-1)).
  • Reading an index that doesn't exist gives undefined.
  • const arrays can still have their contents changed. You just can't replace the whole array.
  • push/pop add/remove at the end. unshift/shift add/remove at the start.
  • includes checks if an item exists. indexOf finds its position (or -1).
  • slice copies part of an array (original unchanged). splice removes/inserts items in the original.
  • Loop with for (let i = 0; i < arr.length; i++) when you need the index, or for...of when you just need the items.
  • split turns a string into an array. join turns an array into a string.
  • Spread ([...arr]) copies or combines arrays. Plain assignment (b = a) does not copy; both names share one array.
  • sort() sorts as text by default! For numbers, use sort((a, b) => a - b).
  • Arrays can contain arrays, which is great for grids: grid[row][col].

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning