Arrays – Creation and Indexing, online

Six activities your students do on their own devices. See who's finished, and their scores.

Arrays – Creation and Indexing in one minute

What students need to know

Since indexing starts at 0, index 1 is the second element. JavaScript arrays are zero-based, so 0 is the first index.

Square brackets create a new array. Arrays use square brackets [], not curly braces.

Mistakes students make

  • Arrays use square brackets [], not round brackets ().
  • Index access uses square brackets, not round brackets.
  • Index access uses square brackets, not curly braces.
  • Arrays use square brackets [], not curly braces {}.
PREVIOUS · MODULE 21break and continue
YOU ARE HERE · MODULE 22Arrays – Creation and Indexing
NEXT · MODULE 23for...of Loops

Discover other journeys with this module

What students will learn in this module

Every question in Module 22

Quick questions

  1. Does [] create an array in JavaScript?ANoBYes
  2. Is the first element of an array at index 0?ANoBYes
  3. Is () used to access an element by index?ANoBYes
  4. Does fruits[1] access the second element of the array?AYesBNo
  5. Are curly braces {} used to create an array?ANoBYes

Key terms

Students type the meaning of:

  • []

Match the pairs

["apple", "banana", "cherry"]Match it to what it does
fruits[0]Match it to what it does
Accesses the second element of an arrayMatch it to what it does
The starting index for the first element in an arrayMatch it to what it does
let a = (1, 2, 3);Match it to what it does
console.log(fruits(0));Match it to what it does

Fill in the blanks

  1. let fruits = _"apple", "banana"_;

    Hint: Type the symbol that opens an array.

  2. console.log(fruits_0_);

    Hint: Type the symbol that opens an index access.

  3. let colors = ["red", "blue"];
    console.log(colors_1]);

    Hint: Type the symbol that opens an index access.

  4. let nums = [1, 2, 3];
    console.log(nums[_]);

    Hint: Type the index number of the first element.

  5. let sizes = [10, 20, 30];
    console.log(sizes[_]);

    Hint: Type the index number of the third element.

Spot the error

Question 1

Alet a = (1, 2, 3);Bconsole.log(a[0]);Clet b = [4, 5];

Question 2

Alet c = [1, 2, 3];Bconsole.log(c(0));Clet d = [4, 5];

Question 3

Aconsole.log(names{0});Blet names = ["Amy", "Bob"];Cconsole.log(names[1]);

Question 4

Alet e = {1, 2, 3};Bconsole.log(e[0]);Clet f = [4, 5];

Question 5

Alet colors = ["red", "blue"];Bconsole.log(colors[1)Cconsole.log(colors[1]);