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 ListsImmutability 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 ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraConditional StatementsWhile LoopsFor LoopsArrays and ListsArray Indexing and Bounds

Longest path: 77 steps · 326 total prerequisite topics

Prerequisites (1)

Leads To (2)