Arrays – Creation and Indexing

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Arrays – Creation and Indexing

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

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

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1["apple", "banana", "cherry"] AWrong - arrays use square brackets, not round brackets
2fruits[0] Bcolors[1]
3Accesses the second element of an array CWrong - index access uses square brackets, not round brackets
4The starting index for the first element in an array DCreates an array holding three string values
5let a = (1, 2, 3); EAccesses the first element of the fruits array
6console.log(fruits(0)); F0

Definitions

[]

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let fruits = _"apple", "banana"_;
2.
console.log(fruits_0_);
3.
let colors = ["red", "blue"]; console.log(colors_1]);
4.
let nums = [1, 2, 3]; console.log(nums[_]);
5.
let sizes = [10, 20, 30]; console.log(sizes[_]);

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let a = (1, 2, 3);
B console.log(a[0]);
C let b = [4, 5];
Question 2
A let c = [1, 2, 3];
B console.log(c(0));
C let d = [4, 5];
Question 3
A console.log(names{0});
B let names = ["Amy", "Bob"];
C console.log(names[1]);
Question 4
A let e = {1, 2, 3};
B console.log(e[0]);
C let f = [4, 5];
Question 5
A let colors = ["red", "blue"];
B console.log(colors[1)
C console.log(colors[1]);

Answer Key

Arrays – Creation and Indexing
Section A: Quick Questions
Q1
B — Yes
Q2
B — Yes
Q3
A — No
Q4
A — Yes
Q5
A — No
Section B: Match the Pairs
Q1
["apple", "banana", "cherry"] → Creates an array holding three string values
Q2
fruits[0] → Accesses the first element of the fruits array
Q3
Accesses the second element of an array → colors[1]
Q4
The starting index for the first element in an array → 0
Q5
let a = (1, 2, 3); → Wrong - arrays use square brackets, not round brackets
Q6
console.log(fruits(0)); → Wrong - index access uses square brackets, not round brackets
Section C: Definitions
Q1
[] — Creates an array and, when placed after a variable name, accesses an element by its index.
Section D: Fill in the Blanks
Q1
let fruits = ["apple", "banana"];
Q2
console.log(fruits[0]);
Q3
let colors = ["red", "blue"]; console.log(colors[1]);
Q4
let nums = [1, 2, 3]; console.log(nums[0]);
Q5
let sizes = [10, 20, 30]; console.log(sizes[2]);
Section E: Spot the Error
Q1
A — Arrays use square brackets [], not round brackets ().
Q2
B — Index access uses square brackets, not round brackets.
Q3
A — Index access uses square brackets, not curly braces.
Q4
A — Arrays use square brackets [], not curly braces {}.
Q5
B — The index access is missing its closing square bracket.