JavaScript Array

Beginner
8 min read
Updated: Nov 2026
3 examples
Ordered lists

Definition and Usage

In JavaScript, an Array is an ordered list of values. You write one with square brackets: ["red", "green", "blue"]. Each value is an element. The first element is at index 0.

length is a property, so you read it without parentheses: colors.length. Methods do the work of changing or copying the list. push() adds to the same array. map() and filter() return a new array and leave the original alone. Array.isArray(value) is the check for “is this a list?”, because typeof [] is "object".

This page teaches what an Array is. The Array Methods index and Array Properties index list every method and property guide (push(), map(), length, and more).

Index 0 is the first item.

colors[0] is the first element. colors.at(-1) is the last. colors[colors.length] is undefined.

JavaScript Syntax

Common ways to create and read an array:

JavaScript
const colors = ["red", "green", "blue"];
const first = colors[0];          // "red"
const count = colors.length;      // 3
const last = colors.at(-1);       // "blue"
const copy = colors.slice();      // new array, same items
const ok = Array.isArray(colors); // true

Core Ideas

Ideas every JavaScript Array tutorial builds on:

IdeaExampleRemember
Literal["red", "green"]Ordered list of any values
Indexcolors[0]First item is index 0
lengthcolors.lengthA property, not a method
Addcolors.push("gold")Changes that same array
Copynums.map(...)Returns a new array
CheckArray.isArray(x)typeof [] is "object"

JavaScript Examples

Three short programs that show how Array works in a JS tutorial.

Example 1 — Index, length, and the last item

The first element is 0. at(-1) counts from the end.

JavaScript
const colors = ["red", "green", "blue"];

console.log(colors[0]);
console.log(colors.length);
console.log(colors.at(-1));
at() tutorial

How It Works

  1. colors[0] is "red", the first element.
  2. length is 3 because there are three elements.
  3. at(-1) is "blue", the last element.

Example 2 — map() copies, push() changes

Keep the doubled list in a new variable. push edits nums.

JavaScript
const nums = [1, 2, 3];
const doubled = nums.map(function (n) {
  return n * 2;
});

nums.push(4);
console.log(nums.join(","));
console.log(doubled.join(","));
map() tutorial

How It Works

  1. map() returns [2, 4, 6] and does not edit nums.
  2. push(4) adds 4 to the end of nums.
  3. join(",") prints the two lists so you can see they diverged.

Example 3 — Keep the passing scores

filter() builds a new array. Array.isArray confirms it is a list.

JavaScript
const scores = [10, 40, 70];
const passed = scores.filter(function (n) {
  return n >= 40;
});

console.log(passed.join(","));
console.log(Array.isArray(passed));
console.log(Array.isArray("40"));
filter() tutorial

How It Works

  1. filter() keeps 40 and 70. 10 fails the test.
  2. scores is still [10, 40, 70]. The result lives in passed.
  3. Array.isArray("40") is false. A string is not an array.

Next: Methods & Properties Indexes

After you know what an Array is, open the indexes for full tutorials on every essential Array API in this JavaScript series.

Start withWhy
push()Add an item to the end
map()Build a new array from each item
filter()Keep only the items that pass a test
find()Return the first matching item

Full lists: Array Methods index and Array Properties index.

Frequently Asked Questions

An Array is an ordered list of values. You write it with square brackets: ["red", "green", "blue"]. The first item is at index 0. length tells you how many items are in the list.
Yes. colors[0] is the first item and colors[colors.length - 1] is the last. colors.at(-1) also reads the last item. There is no item at colors[colors.length].
Some do. push(), pop(), splice(), and sort() change the same array. map(), filter(), slice(), and concat() return a new array and leave the original in place.
Use Array.isArray(value). typeof [] is "object", so typeof cannot tell an array from a plain object.
Practice the examples here, then open the Array Methods index for push(), map(), filter(), and find(). The Array Properties index explains length, constructor, and Array.prototype.

Browse every Array method

Open the index for push(), map(), filter(), find(), and the rest.

Array Methods index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

16 people found this page helpful