The MDN documentation for Set says that JavaScript Set
objects retain insertion order of elements:
(Set的MDN文档说JavaScript Set
对象保留元素的插入顺序:)
Set objects are collections of values, you can iterate its elements in insertion order.
(集合对象是值的集合,可以按插入顺序对其元素进行迭代。)
Is there a way to get the last item inserted into a Set
object?
(有没有一种方法可以将最后一个项目插入Set
对象中?)
var s = new Set();
s.add("Alpha");
s.add("Zeta");
s.add("Beta");
console.log(getLastItem(s)); // prints "Beta"
Edit
(编辑)
It is possible to implement a Linked Set datastructure container class that has the same interface as Set
and has the desired capability.
(它可以实现具有相同的接口,一组链接数据结构容器类Set
并具有所需的能力。)
(请参阅下面的答案。)
ask by Tamas Hegedus translate from so