DEV Community

Discussion on: How to shift array position in vanilla JavaScript

Collapse
 
bgadrian profile image
Adrian B.G.

Probably that array is not going to be accessed using the index, it looks like an unordered collection.

If this is true you need a linked list not an array, making the move operation 2N more efficient and resulting in a simpler code.

Collapse
 
thejoezack profile image
Joe Zack

Great point! Array Data Structures aren't very efficient at arbitrarily inserting or plucking (even though JS provides convenient shift/deshift methods.)

With this small of a dataset it doesn't matter, but it's a great point. :)