Glossary · Programming

Array (Data Structure)

An array is a data structure that stores elements in contiguous memory and lets you access each one instantly by its numeric index.

Updated October 6, 2026

An array is a data structure that holds a sequence of elements, usually of the same type, in contiguous memory. Each element is reached by its numeric index, and most languages start counting at 0.

Why it matters

Because elements are laid out side by side, the computer can calculate any element's address directly, making reads and writes by index O(1). Sequential access is also very cache friendly, which makes arrays fast in practice. The drawbacks are that inserting or deleting in the middle requires shifting later elements (O(n)), and fixed-size arrays cannot grow. Many languages provide dynamic arrays, such as Python lists, Java ArrayList and C++ vector, that resize automatically by allocating a larger block and copying.

Example

const codes = [200, 301, 404, 500];
codes[2];          // 404 (index 2, the third element)
codes.length;      // 4
codes.push(503);   // append at the end

Common mistakes

  • Off-by-one errors, such as looping to length inclusive instead of length - 1.
  • Reading outside the bounds, which is an error in safe languages and undefined behavior in C.
  • Using includes or indexOf repeatedly on large arrays where a set or hash table would be faster.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.