Learn JavaScript
❯ arrays.arrays_basics

Arrays & Essential Properties in JavaScript

$concept

JavaScript arrays are dynamic, heterogeneous, zero-indexed lists: [1, "two", true] is legal, .length tracks one past the last index (and truncates on assignment!), and holes (sparse arrays from delete or [1,,3]) read as undefined. They are objects underneath β€” typeof [] is "object" β€” which is why Array.isArray exists as the only reliable check.

Core properties beyond length: indexes are string keys really (arr[0] === arr["0"]), assignment past the end extends automatically, and setting length smaller deletes tail elements. These semantics make arrays flexible and occasionally surprising β€” know them before the methods.

$how it works
1

Dynamic and mixed

Any values, any length, growable by assignment β€” [1, "two"] with arr[5] = x extending through holes.

2

length is live

Always one past the last index; assigning smaller truncates (arr.length = 0 empties!), larger extends sparsely.

3

Objects underneath

typeof [] is "object" β€” indexes are really string keys, which Array.isArray (not typeof) distinguishes.

4

Holes read undefined

Sparse slots ([1,,3][1]) yield undefined on read β€” distinct from explicitly stored undefined in some methods.

$example
let a = [10, 20, 30];
console.log(a.length, a[1]);
a.length = 2;
console.log(a.length, Array.isArray(a));
Output
3 20
2 true
1Three elements: length 3, index 1 holds 20.
2Assigning length 2 truncates the tail β€” 30 is gone, not hidden.
3Array.isArray confirms array-ness where typeof would only say object.
$use cases
Checking Array.isArray before array-only operations on unknown input
Emptying arrays in place with arr.length = 0
Understanding sparse-array behavior in legacy code
Growing arrays by direct index assignment

Recommended resourcesAffiliate links Β· may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice β€” pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from β€” great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself β€” building beats watching.