Skip to content

Array

In one line

An array is an ordered list of values, accessed by numeric index starting at 0.

In simple words

An array is a list of values stored in a single variable. Each value (element) has a numeric position (index) starting at 0. Arrays can hold any type of value — numbers, strings, objects, even other arrays.

JavaScript arrays are dynamic — they can grow and shrink. Common methods include push (add to end), pop (remove from end), map (transform each element), filter (keep matching elements), and reduce (combine into one value).

Arrays are reference types — assigning an array to a new variable does not copy it; both point to the same array. To copy, use the spread operator [...arr] or arr.slice().

Example

javascript
const fruits = ["apple", "banana", "cherry"];
console.log(fruits[0]);       // "apple"
console.log(fruits.length);   // 3
fruits.push("date");
console.log(fruits.length);   // 4

Arrays use zero-based indexing and have a length property.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary