Skip to main content

Array

In Turkish
Dizi
Pronunciation
uh-RAY
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/array

In short

An array is an ordered collection of values stored under one name, where each item is accessed by its numeric position, called an index, usually starting at 0.

What is an array?

An array holds multiple values in a specific order, such as a list of usernames or a series of temperature readings. Instead of creating a separate variable for each item, you store them all in one array and refer to each item by its index. In most languages, including JavaScript, Python, Java, and C, the first item is at index 0, the second at index 1, and so on.

In low-level languages like C, an array is a fixed-size block of memory where the items sit right next to each other. Because every slot has the same size, the computer can jump straight to any index with simple arithmetic, so reading items[500] is just as fast as reading items[0], which is described as O(1), or constant time. Higher-level languages usually provide dynamic arrays, such as JavaScript arrays, Python lists, and Java's ArrayList, which grow automatically as you add items.

A row of numbered mailboxes is a good analogy for an array: every box has a number, the boxes are in order, and you can go directly to box 7 without opening the first six. Arrays are used almost everywhere in programming, from holding the rows returned by a database query to storing the pixels of an image. They are commonly processed with loops or with methods like map, filter, and reduce.

Arrays are often compared with linked lists and with objects or dictionaries. Adding or removing items at the start or in the middle of an array is slow, because all the later items must shift over, while a linked list can do this cheaply but cannot jump directly to an index. An object or dictionary, by contrast, stores values under named keys instead of numeric positions.

At a glance

An array keeps its items side by side in memory, numbered from index 0. Reading arr[3] jumps straight to it, however long the array is; inserting at the front moves every item one place along.index0123473941memory10001004100810121016arr[3]: straight there, O(1)insert 5 at the frontevery item moves one place: O(n)573941
Because the items sit next to each other, the computer works out where arr[i] is in one step: O(1). Inserting or removing at the start is O(n).

Key takeaways

  • An array stores an ordered list of values under one name.
  • Items are accessed by index, which usually starts at 0.
  • Reading an item by index is fast, O(1), no matter how large the array is.
  • Inserting or removing items at the start or middle is slower because other items must shift.
  • Dynamic arrays, like JavaScript arrays and Python lists, resize automatically.

Example

Working with an array in JavaScriptjavascript
// Create an array of three strings
const fruits = ["apple", "banana", "cherry"];

console.log(fruits[0]);     // "apple" (indexes start at 0)
console.log(fruits.length); // 3

fruits.push("date");        // add an item to the end
fruits[1] = "blueberry";    // replace an item by its index

// Build a new array by transforming each item
const upper = fruits.map((fruit) => fruit.toUpperCase());
console.log(upper); // ["APPLE", "BLUEBERRY", "CHERRY", "DATE"]

Readers ask

Why do arrays start at index 0?

In languages like C, an index is the distance, or offset, from the start of the array in memory, so the first item is zero steps away. Most later languages kept this convention, although a few, such as Lua, MATLAB, and R, start counting at 1.

What is the difference between an array and a list?

The terms overlap. Classically, an array is a fixed-size block of contiguous memory, while a list can grow and shrink; Python's list and JavaScript's Array are actually dynamic arrays that combine fast index access with automatic resizing.

How do I check if a value is an array in JavaScript?

Use Array.isArray(value), which returns true only for arrays. The typeof operator doesn't help here, because it returns "object" for arrays as well as for plain objects.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings