A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Array Indexing and Bounds

College Depth 76 in the knowledge graph ☐ I know this ☆ Set as goal
532topics build on this
326prerequisites beneath it
See this on the map →
Arrays and Lists→→Immutability and MutationIterating Over Collections
arrays indexing bounds

Core Idea

Indexing accesses array elements by position using bracket notation (e.g., arr[0]). Valid indices range from 0 to length-1. Accessing an out-of-bounds index causes an error.

Explainer

Now that you understand arrays as ordered collections of elements, the next question is: how do you get at a specific element? The answer is indexing — using a number inside bracket notation to specify which position you want. If you have an array `fruits = ["apple", "banana", "cherry"]`, then `fruits[0]` gives you `"apple"`, `fruits[1]` gives you `"banana"`, and `fruits[2]` gives you `"cherry"`. The number inside the brackets is called the index.

The critical detail that trips up nearly every beginner is that indexing starts at zero, not one. The first element is at position 0, the second at position 1, and so on. This is called zero-based indexing, and it means the last element in an array of length `n` sits at index `n - 1`. Think of the index as an offset from the beginning: the first element is zero steps from the start, the second is one step from the start. Once this clicks, zero-based indexing feels natural.

What happens when you use an index that doesn't exist? If your array has three elements (indices 0, 1, 2) and you try to access `fruits[3]` or `fruits[-1]` (in languages without negative indexing), the program raises an out-of-bounds error. The array simply has no element at that position, so there is nothing to return. This is one of the most common runtime errors in programming, and it almost always means your index math is off by one — often because you forgot that the last valid index is `length - 1`, not `length`.

Understanding indexing also unlocks a powerful pattern: you can use a variable as the index. Instead of writing `fruits[0]`, you can write `fruits[i]` where `i` is a variable that changes. This is the foundation of iterating through arrays — stepping through each element by incrementing the index from 0 up to `length - 1`. Getting comfortable with index arithmetic now will make loops over collections feel straightforward when you encounter them next.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Conditional Statements → While Loops → For Loops → Arrays and Lists → Array Indexing and Bounds

Longest path: 77 steps · 326 total prerequisite topics

Prerequisites (1)

Leads To (2)