Hacker News new | ask | show | jobs
How JavaScript Array Works Internally? (blog.gauravthakur.in)
8 points by ScottWRobinson 1566 days ago
2 comments

Nowadays JSC and V8 both store objects and arrays the same way at this point, the only difference is the magic behavior of the length property that’s exposed.

Shift and unshift attempt to just move a pointer into the numeric storage of the object rather than

> Avoid giving the initial capacity to the array

This isn’t necessarily right. It’s perfectly fine to do:

  Array(n).fill()
Which returns a dense array.
It performs a copy, does nothing to the initial array.