What you’ll learn
- What arrays are and how to create them
- Why counting starts at zero
- Reading, changing and counting items
- Adding and removing with
push,pop,shift,unshift - Finding items with
includesandindexOf slicevssplice- Looping through arrays
- Splitting, joining, sorting and copying
- Arrays inside arrays (grids!)
The pages
Fourteen pages, about 16 minutes.
- What Is an Array? Imagine you're keeping track of your favorite foods. With what you know so far, you'd do something like this. That's…
- Reading Items (and Why We Count From Zero) To get an item out of an array, write the array's name followed by the item's index in square brackets. And just like…
- length and the Last Item Every array knows how many items it has, through its length. Since indexes start at 0, the last item is always at…
- Changing Items You can replace an item by assigning a new value to its index. Wait a minute! We created foods with const. Isn't that…
- Adding and Removing Items Arrays come with built-in methods for adding and removing items at either end. There are four, and they come in pairs.
- Finding Things in an Array Need to know if something's in your array? Use includes, just like with strings. Perfect for a bouncer at a party. "Is…
- Slicing and Splicing These two methods have almost the same name, which is deeply unfair, because they do very different things…
- Looping Over Arrays This is where arrays and loops become best friends. Since arrays have a length and numbered indexes, a for loop can…
- Arrays and Strings: split and join Strings and arrays are close cousins, and you can easily turn one into the other. split(separator) chops a string into…
- Combining and Copying Arrays To combine arrays, you can use concat, or the modern spread syntax ..., which "spreads out" all the items of an array…
- Sorting Arrays (and a Sneaky Surprise) The sort() method puts an array in order. With strings, it sorts alphabetically. Easy. Now let's sort some numbers…
- Arrays Inside Arrays An array can contain other arrays! This is perfect for anything that's shaped like a grid: a game board, a…
- Mini Project: The Shopping List Manager Let's combine arrays and functions into a little shopping list program. Notice how each function has one clear job…
- Recap The key ideas of Grade 7, JavaScript arrays, on one page. An array is an ordered list of values, written with square…
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.