Reputation: 53
We be learning about arrays in computer science and how they occupy a continuous range of memory space.
In a pure array you cannot add and remove elements without shifting other elements.
So when I do:
const arr = ['a', 'b', 'd'];
arr.splice(2, 0, 'c'); // arr is now ['a', 'b', 'c', 'd']
I am not performing an array operation and arrays must be implemented in some other way in JavaScript?
Perhaps a linked list?
I'm not asking for a specification, just in a typical implementation of the language in the browser or Node, what are they likely using?
This 10 year old+ Q/A touches on the subject but does not answer it, so please do not mark as a duplicate.
The actual underlying representation may differ between browsers (or it may not).
What is the most likely underlying data structure used?
Upvotes: 5
Views: 1306
Reputation: 56
The array is not just implemented in one way. It depends upon what you put in to it, numbers, other arrays or objects, etc.
The JavaScript engine then decides at run-time how to implement it.
The two most common are C++ arrays and Linked Lists.
See here for more information.
Upvotes: 4