An Array is an ordered list of values in JavaScript. Unlike static arrays in C or Java that have fixed memory capacities and rigid data types, JavaScript arrays are dynamic objects capable of growing or shrinking automatically and storing heterogeneous data types simultaneously.
Figure 4: JavaScript Array taxonomy: Mutator methods vs Accessor methods vs Functional Iterator methods.
// 1. Array Literal Syntax (Preferred Industry Standard)
const fruits = ["Apple", "Mango", "Banana"];
// 2. Heterogeneous Array (Mixed Types)
const mixedData = ["Veewom", 2026, true, { role: "admin" }, [1, 2, 3]];
// 3. Array Constructor
const emptySlots = new Array(5); // Creates sparse array with 5 empty slots
console.log(emptySlots.length); // 5
Arrays use zero-based indexing (first element at index 0, last at array.length - 1):
const colors = ["Red", "Green", "Blue", "Yellow"];
console.log(colors[0]); // "Red"
console.log(colors[colors.length - 1]); // "Yellow" (Last element)
console.log(colors.at(-1)); // "Yellow" (Modern ES2022 negative index API!)
// TRUNCATING WITH LENGTH PROPERTY
colors.length = 2; // Truncates elements beyond index 1!
console.log(colors); // ["Red", "Green"]
Exam Question: "What are Sparse Arrays and Dense Arrays in JavaScript? How does V8 optimize them?"
Dense Arrays: Elements occupy continuous, sequential index slots without gaps (e.g. [10, 20, 30]). V8 stores dense arrays as high-speed contiguous C++ buffers.
Sparse Arrays: Contain empty gaps/holes between indices (e.g., let a = []; a[0] = 1; a[100] = 5;). V8 handles sparse arrays as dictionary hash tables with property keys, which increases memory overhead and slows execution.
How do you insert, delete, and rearrange elements inside arrays? Proceed to: JavaScript Array Mutator Methods: push, pop, splice & sort →
Accelerate your JavaScript mastery by studying these tightly connected core tutorials:
push, pop, shift, unshift, splice, and slice.
Functional declarative data transformations.
Unpacking array values into distinct variables.
Cloning and merging arrays with ease.