Arrays are ordered lists—zero-indexed, growable, and passed by reference.
Core operations
push/pop— endunshift/shift— startlength, index accessarr[i]at(-1)— last element
Copy pitfalls
const a = [1]; const b = a; shares reference—use spread [...a] or structuredClone for copies.
Important interview questions and answers
- Q: Array vs object?
A: Arrays are objects with numeric keys and length property. - Q: mutate const array?
A: Allowed—const prevents rebinding, not inner mutation.
Self-check
- How get last element with at()?
- Why spread for copy?
Tip: [...arr] shallow-copies—nested arrays need structuredClone.
Interview prep
- Copy array?
Use spread or slice for shallow copy.