Javascript list such as data structure?

It seems, if I'm not mistaken, due to the fact that Javascript processes objects, it is impractical or inefficient for implementing linked lists.

I need a data structure in which I could easily perform 2 operations (except indexing), add to the end and delete (pop out) an object at a given index.

Uses Array and "recreates" it for each operation of removal the optimal solution? I would not have thought.

Any ideas?

+6
javascript arrays
source share
3 answers

It seems that JS Array is exactly what you are looking for.
You should be able to use the push and pop functions for a data structure similar to the stack, and splice for the rest.

+4
source share

In fact, Array supports push and pop operations: JavaScript Array Object

+3
source share

You do not need to recreate a Javascript array for each deletion. Javascript arrays have push() and pop() methods for adding and removing elements:

JavaScript Array Object

+1
source share

All Articles