Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JavaScript · Class

Array

The JavaScript Array object stores an ordered collection of values under one variable name. Arrays are zero-indexed, resizable, can mix value types, and provide methods for common collection operations.

How it works

JavaScript's Array object represents an ordered, indexed collection. Arrays can resize, hold values of different types, and provide instance methods plus static helpers for common operations; indexing starts at zero, and standard copying operations produce shallow copies.

Syntax

new Array(element0, element1, /* … , */ elementN)
Array(element0, element1, /* … , */ elementN)
[element0, element1, /* … , */ elementN]

Returns

Array instances are returned by the constructor and conversion helpers; individual members return operation-specific values.

Key points

  • An Array can grow or shrink and can contain heterogeneous values such as numbers, strings, objects, and other arrays.
  • The first element uses index 0; subsequent elements increase the index by one.
  • For a nonempty array, the final element is found at array.length - 1.
  • Calling Array() or using array-literal syntax creates an Array object.
  • Array.from() converts supported iterable or array-like input into a new array.
  • Array.isArray(value) is the direct built-in test for whether a value is an Array.

Common mistakes

  • Do not use arbitrary strings as array indexes; array elements are accessed with nonnegative integer indexes or their string forms.
  • Copying an array does not recursively clone nested objects or arrays, so mutations inside shared nested values remain visible through both arrays.

Example: Create, transform, and access an array

const values = [1, 2, 3];
const doubled = values.map((value) => value * 2);

console.log(doubled); // [2, 4, 6]
console.log(values[0]); // 1

Creates an array, transforms each element into a new array, and accesses the first element by its zero-based index.

When to use it

Collections

Represent an ordered sequence of values for iteration and indexed access.

Data processing

Transform or filter records while preserving a collection-oriented workflow.

Interoperability

Convert iterable or array-like input into a conventional JavaScript array.

Interview questions

QWhat is a JavaScript Array?

Array is an object representing a collection of multiple items under one variable name. It is zero-indexed, resizable, and may contain values of different types.

Follow-up: How would you avoid shared nested state when copying an array? Use an explicit deep-copy strategy; ordinary array-copy operations are shallow.

QHow are Array elements indexed?

The first element is at index 0, and the last element is at length - 1. Accessing an element uses bracket notation, such as items[0].

Follow-up: What happens when the requested index is outside the populated range? The result is undefined, rather than an associative lookup by an arbitrary string.

QName two useful static Array methods.

Array.from() creates a new Array instance from an iterable or array-like object. Array.isArray() returns true for arrays and false otherwise.

Follow-up: Why can Array.from() still leave nested objects shared? The resulting array is a shallow copy of the referenced values.

  • Array()
  • Array.from()
  • Array.fromAsync()
  • Array.isArray()
  • Array.prototype.concat()
  • Array.prototype.every()
  • Array.prototype.find()
  • Array.prototype.indexOf()

Source: Array - JavaScript | MDN. Checked 2026-10-15.