🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
JS MASTER CLASS /// MASTER THE ENGINE /// BUILD LOGIC /// ASYNC PATTERNS /// JS MASTER CLASS /// MASTER THE ENGINE ///
Total XP: 0|💻 javascript XP: 0

JavaScript Arrays: Create, Access, Mutate & Iterate Ordered Collections

Master JavaScript arrays: create them with [], access elements via zero-based indexing, manage size with .length, mutate with push/pop/splice, copy safely with slice, and iterate with for...of and forEach.

LOADING ENGINE...

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Collection Architecture

The complete system for creating, accessing, mutating, and iterating ordered data collections in JavaScript.


Arrays are JavaScript's fundamental ordered data structure. They let you group related values into a single, ordered list that can be accessed by index, resized dynamically, and iterated with modern loop patterns.

1Creating Arrays with Square Brackets

An array is an ordered collection created with square brackets []. Each value is separated by a comma. JavaScript arrays are dynamic — no fixed size declaration — and can hold any mix of types: strings, numbers, booleans, objects, and even other arrays.

2Zero-Based Indexing and Bracket Notation

Every element in an array has a numeric position called an index, starting at 0. Access any element with bracket notation: arr[0] for the first, arr[arr.length - 1] for the last. Accessing an index that doesn't exist returns undefined — no error is thrown.

3The .length Property — Dynamic Size Tracking

Every array has a .length property that automatically reflects the current element count. Push an item and length increases. Pop one and it decreases. The last element is always at arr[arr.length - 1], or use the modern arr.at(-1) (ES2022).

4push, pop, shift, unshift — Stack & Queue Patterns

Four methods control the ends of an array. push() adds to the end, pop() removes from the end — this is the stack pattern (last in, first out). unshift() adds to the start, shift() removes from the start — this is the queue pattern (first in, first out). All four mutate the original array.

5splice() — Insert, Remove, or Replace at Any Position

splice() is the most versatile mutation method. It takes three types of arguments: the start index, the number of items to delete, and items to insert. With these you can remove from the middle, insert at any position, or swap elements.

6slice vs splice — Immutable Copy vs Mutable Edit

slice() copies a portion of the array into a new array — the original is never touched (immutable). splice() modifies the original array directly (mutable). Mnemonic: the p in splice means it permanently changes the array.

7Iterating Arrays: for...of and forEach

for...of iterates directly over values — clean, modern, and supports break. .forEach() takes a callback receiving (value, index, array) — ideal when you need the index. forEach always returns undefined and cannot use break.

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Lesson Glossary

[01]Array

An ordered collection of values stored in a single variable, created with square brackets []. Each value occupies a numbered position (index) starting at 0.

Code Preview
const arr = ['A', 'B', 'C'];

[02]Index

The numeric position of an element in an array, starting at 0. The last index is always array.length - 1.

Code Preview
arr[0] // first element

[03]Zero-Based Indexing

The convention of numbering array positions from 0 instead of 1. Index 0 = first element, index 1 = second element. Standard in JavaScript and most languages.

Code Preview
arr[0] // ← position 0 is the first slot

[04].length

A built-in property that always equals the current number of elements. Updates automatically when items are added or removed.

Code Preview
arr.length // → number of elements

[05]push()

Adds one or more elements to the END of an array. Returns the new length. Mutates the original array.

Code Preview
arr.push('new') // add to end

[06]pop()

Removes the LAST element from an array and returns it. Mutates the original array.

Code Preview
const last = arr.pop(); // remove last

[07]shift()

Removes the FIRST element from an array and returns it. Re-indexes all remaining elements (slower than pop on large arrays).

Code Preview
const first = arr.shift(); // remove first

[08]unshift()

Adds one or more elements to the START of an array. Returns the new length. Re-indexes all elements.

Code Preview
arr.unshift('new') // add to start

[09]splice()

Inserts, removes, or replaces elements at any position. Takes (start, deleteCount, ...items). Mutates the original array.

Code Preview
arr.splice(1, 2, 'X') // at index 1, remove 2, insert 'X'

[10]slice()

Returns a shallow copy of a portion of an array into a new array. Does NOT modify the original (immutable). End index is exclusive.

Code Preview
const copy = arr.slice(1, 3) // copies index 1,2

[11]Nested Array

An array containing other arrays as elements, enabling 2D or multi-dimensional data structures like grids, matrices, and tables.

Code Preview
grid[row][col] // double bracket access

[12]Iteration

The process of executing code once for every element in an array. Common patterns: for...of (values), forEach (value + index), classic for (full control).

Code Preview
for (const item of arr) { ... }

Continue Learning