Arrays solve the problem of storing multiple values in a single, organized place so we can easily access and manage them by their position.
Click to reveal answer
beginner
How does an array help compared to using separate variables for each value?
An array groups many values under one name and uses numbers (indexes) to find each value, making code simpler and easier to manage than many separate variables.
Click to reveal answer
beginner
What is an index in an array?
An index is a number that shows the position of a value inside an array, starting from 0 for the first value.
Click to reveal answer
beginner
Why is it useful that arrays store values in order?
Storing values in order lets us quickly find, add, or change values by their position, like finding a book on a shelf by its place.
Click to reveal answer
beginner
What would happen if we didn’t have arrays and had to store many values?
Without arrays, we would need many separate variables, making code long, confusing, and hard to update or search through.
Click to reveal answer
What does an array store?
AMultiple values in one place
BOnly one value
CFunctions only
DRandom unrelated data
✗ Incorrect
Arrays store multiple values together so we can manage them easily.
What is the first index number in an array?
A1
B0
C-1
DDepends on the array
✗ Incorrect
Array indexes start at 0, so the first value is at position 0.
Why are arrays better than many separate variables?
AThey group values and make code simpler
BThey use less memory
CThey run faster
DThey store only numbers
✗ Incorrect
Arrays group values under one name and use indexes, making code easier to write and read.
What problem does an array solve?
AStoring one value
BSorting values automatically
CStoring multiple values in order
DMaking code longer
✗ Incorrect
Arrays store many values in order so we can access them by position.
If you want to find the 3rd item in a list stored in an array, which index do you use?
A3
B0
C1
D2
✗ Incorrect
Since indexes start at 0, the 3rd item is at index 2.
Explain why arrays are useful and what problem they solve in simple terms.
Think about how you keep many books on a shelf instead of one by one.
You got /4 concepts.
Describe what an index is in an array and why it matters.
Imagine counting seats in a row starting from zero.
You got /4 concepts.
Practice
(1/5)
1. Why do arrays exist in programming languages like TypeScript?
easy
A. To store multiple values in a single, ordered collection
B. To perform mathematical calculations automatically
C. To replace all other data structures like trees and graphs
D. To store only one value at a time
Solution
Step 1: Understand the purpose of arrays
Arrays are designed to hold many values together in one place, keeping them in order.
Step 2: Compare with other options
Options A, B, and D do not describe arrays correctly. Arrays do not perform calculations automatically, do not replace all data structures, and can hold more than one value.
Final Answer:
To store multiple values in a single, ordered collection -> Option A
Quick Check:
Arrays store many values in order = C [OK]
Hint: Arrays hold many values together in order [OK]
Common Mistakes:
Thinking arrays store only one value
Confusing arrays with calculation tools
Believing arrays replace all data structures
2. Which of the following is the correct way to declare an array of numbers in TypeScript?
easy
A. let nums: number[] = [1, 2, 3];
B. let nums = (1, 2, 3);
C. let nums: number = [1, 2, 3];
D. let nums: array = 1, 2, 3;
Solution
Step 1: Check TypeScript array syntax
In TypeScript, arrays are declared with type followed by square brackets, e.g., number[].
Step 2: Validate each option
let nums: number[] = [1, 2, 3]; uses correct syntax. Options B, C, and D have syntax errors or wrong type declarations.
Final Answer:
let nums: number[] = [1, 2, 3]; -> Option A
Quick Check:
Correct array syntax = A [OK]
Hint: Use type[] to declare arrays in TypeScript [OK]
Common Mistakes:
Using parentheses instead of brackets
Assigning array to a single number type
Incorrect type keyword usage
3. What will be the output of the following TypeScript code?
The push method adds a new element to the end of the array.
Step 2: Apply push to the array
Starting with [10, 20, 30], pushing 40 results in [10, 20, 30, 40].
Final Answer:
[10, 20, 30, 40] -> Option B
Quick Check:
push adds element at end = D [OK]
Hint: push adds element to array end [OK]
Common Mistakes:
Thinking push adds element at start
Expecting original array unchanged
Confusing push with pop
4. Identify the error in this TypeScript code that tries to create an array and add an element:
let numbers = 5;
numbers.push(10);
medium
A. Array must be declared with 'const' keyword
B. push method requires two arguments
C. Variable 'numbers' is not an array, so push method is invalid
D. Numbers cannot be stored in arrays
Solution
Step 1: Check variable type
Variable 'numbers' is assigned a single number, not an array.
Step 2: Understand push method usage
push is a method for arrays only, so calling it on a number causes an error.
Final Answer:
Variable 'numbers' is not an array, so push method is invalid -> Option C
Quick Check:
push only works on arrays = A [OK]
Hint: push works only on arrays, not single values [OK]
Common Mistakes:
Assuming push works on numbers
Thinking push needs multiple arguments
Believing arrays must be const
5. You want to store daily temperatures for a week and quickly access any day's temperature by its position. Which data structure solves this problem best and why?
hard
A. Linked list, because it uses less memory than arrays
B. Stack, because it stores data in last-in-first-out order
C. Set, because it automatically removes duplicate temperatures
D. Array, because it stores values in order and allows fast access by index
Solution
Step 1: Identify the need for ordered storage and fast access
Storing temperatures by day means order matters and quick access by position is needed.
Step 2: Compare data structures
Arrays keep order and allow direct access by index, making them ideal. Linked lists have slower access, sets remove duplicates (not needed), stacks use LIFO order which is not suitable.
Final Answer:
Array, because it stores values in order and allows fast access by index -> Option D
Quick Check:
Ordered fast access = Array = B [OK]
Hint: Use arrays for ordered data with fast index access [OK]
Common Mistakes:
Choosing linked list for fast access
Using set which removes duplicates unnecessarily
Selecting stack which reverses order
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.