If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Teaching guide: Intro to JS - Arrays

This is a teaching guide for the Intro to JS lesson on Arrays.

What the student will learn

  • How to create arrays to store a sequence of values in one variable.
  • How to access or change elements of an array using “bracket notation”.
  • How to add elements to an array using the push() method.
  • How to iterate through an array using a for loop.

The student will be able to write code like:

Where students struggle

  • Students take time to get used to the fact that arrays start at index 0, since we’re used to counting from 1 in our every day life. Keep reminding them about that.
  • If students didn’t get comfortable using for loops in the last lesson, they will likely struggle to use them in this lesson. If that’s the case, they may want to re-watch the for loop lesson and go through the challenge again.
  • When iterating with a for loop, students often forget to use bracket notation to access the elements of their array, and they instead access the whole array. Ask them whether their code is truly accessing only one element of the array.
  • Students may wonder if there is a method for removing elements from an array. They can use the pop() method for that. There are in fact many array methods we don’t teach in the intro course, which students can find by searching the web for “JS array methods”.
  • Students may wonder if they can create a 2-d array, to store a grid of values. They can certainly do that, but we don't teach that in the intro course. Search for “multi-dimensional JS array” or “2-d JS array” for examples.

Additional materials: Discussion questions

These are questions that you can ask students individually after they've done the lesson, or lead a group discussion around, if everyone's gotten to the same point.
  • What data would be useful to store in an array? Open a popular game or an app for inspiration, and have the students brainstorm.

Additional materials: Trivia questions

These can be fun to do as a class after everyone’s gotten through the lesson. They can also lead to discussion about which questions are the hardest. Play them on Quizizz.

Want to join the conversation?