Arrays & Essential Properties in JavaScript
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.
Dynamic and mixed
Any values, any length, growable by assignment β [1, "two"] with arr[5] = x extending through holes.
length is live
Always one past the last index; assigning smaller truncates (arr.length = 0 empties!), larger extends sparsely.
Objects underneath
typeof [] is "object" β indexes are really string keys, which Array.isArray (not typeof) distinguishes.
Holes read undefined
Sparse slots ([1,,3][1]) yield undefined on read β distinct from explicitly stored undefined in some methods.
let a = [10, 20, 30];console.log(a.length, a[1]);a.length = 2;console.log(a.length, Array.isArray(a));Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself β building beats watching.