Set data structure of Java in javascript/jQuery

后端 未结 5 1743
臣服心动
臣服心动 2021-02-02 10:52

Is there any way to create Set data structure(Unique Collections) like java in javascript?

5条回答
  •  萌比男神i
    2021-02-02 11:29

    I have written a JavaScript implementation of a hash set that is similar to Java's HashSet. It allows any object (not just strings) to be used as a set member. It's based on the keys of a hash table.

    http://code.google.com/p/jshashtable/downloads/list

    Documentation will follow shortly, I promise. For now, the source should give you the API pretty clearly, and here's an example:

    var s = new HashSet();
    var o1 = {name: "One"}, o2 = {name: "Two"};
    s.add(o1);
    s.add(o2);
    s.add(o2);
    s.values(); // Array containing o1 and a single reference to o2
    

提交回复
热议问题