Array
An array is an ordered collection used to store multiple values under one variable or identifier.
Arrays are one of the most common data structures in programming. They are used when related values need to be grouped together in a predictable order.
What it does
An array holds multiple values in one structure.
It is commonly used to:
- Store lists of related items
- Access elements by position or index
- Loop through grouped values
- Pass collections of data between functions or systems
- Represent ordered values in formats such as JSON
Core concepts
Ordered collection
Arrays preserve element order.
That makes them useful when position matters, such as first item, last item, or a sequence of steps.
Indexed access
Array elements are usually accessed by numeric index.
In many languages, indexing starts at 0, though that is language-specific.
Array vs single variable
A normal variable usually stores one value.
An array stores multiple values as one collection.
Common use cases
- Lists of users, products, or files
- Sets of configuration values
- Ordered records from an API response
- Frontend collections rendered in a UI
- Data processing and iteration in scripts and applications
Practical notes
- Arrays are general programming concepts, but the exact behavior depends on the language.
- Some languages use fixed-size arrays, while others provide dynamic or resizable arrays.
- Arrays are good for ordered collections, but not always the best fit for key-value lookup.
- In JSON, arrays are written with square brackets:
[ ... ].
Sources Used
- https://developer.mozilla.org/en-US/docs/Glossary/Array
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Frequently Asked Questions
Is an array the same as a list?
Not exactly. In casual use people often blur them together, but the exact meaning depends on the language and data structure being discussed.
Do arrays always start at index 0?
No. Many languages do, but indexing rules depend on the language or system.
Can arrays store different kinds of values?
Sometimes. That depends on the language and type system being used.