Arrays – Creation and Indexing, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
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
What students will learn in this module
Every question in Module 22
Quick questions
- Does [] create an array in JavaScript?ANoBYes
- Is the first element of an array at index 0?ANoBYes
- Is () used to access an element by index?ANoBYes
- Does fruits[1] access the second element of the array?AYesBNo
- 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 doesfruits[0]Match it to what it doesAccesses the second element of an arrayMatch it to what it doesThe starting index for the first element in an arrayMatch it to what it doeslet a = (1, 2, 3);Match it to what it doesconsole.log(fruits(0));Match it to what it doesFill in the blanks
let fruits = _"apple", "banana"_;
Hint: Type the symbol that opens an array.
console.log(fruits_0_);
Hint: Type the symbol that opens an index access.
let colors = ["red", "blue"]; console.log(colors_1]);
Hint: Type the symbol that opens an index access.
let nums = [1, 2, 3]; console.log(nums[_]);
Hint: Type the index number of the first element.
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]);
