javascript 像数据结构一样的Javascript列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3399263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript list like data structure?
提问by Manux
It seems, if I'm not wrong, that because of the way Javascript handles Objects it is unpractical or inefficient to implement linked lists.
如果我没记错的话,似乎由于 Javascript 处理对象的方式,实现链表是不切实际或低效的。
I would need a data structure in which I could easily do 2 operations(apart from indexing), appending at the end and removing (popping) an object at a given index.
我需要一个数据结构,在其中我可以轻松地执行 2 个操作(除了索引),在末尾追加并删除(弹出)给定索引处的对象。
Is using an Arrayand "recreating" it for each remove operation the optimal solution? I would think not.
使用 anArray并为每个删除操作“重新创建”它是最佳解决方案吗?我想不会。
Any ideas?
有任何想法吗?
采纳答案by Justin
回答by DixonD
Actually Arraysupports pushand popoperations: JavaScript Array Object
实际Array支持push和pop操作:JavaScript Array Object
回答by Justin Niessner
You don't have to recreate the Javascript array for each removal. Javascript Arrays have push()and pop()methods to add and remove elements:
您不必为每次删除重新创建 Javascript 数组。JavaScript数组必须push()和pop()方法来添加和删除元素:

