Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update for 2016</strong></p> <p>Since you're asking about node.js and it is 2016, you can now use either the <code>Set</code> or <code>Map</code> object from ES6 as these are built into ES6. Both allows you to use any string as a key. The <code>Set</code> object is appropriate when you just want to see if the key exists as in:</p> <pre><code>if (mySet.has(someString)) { //code here } </code></pre> <p>And, <code>Map</code> is appropriate when you want to store a value for that key as in:</p> <pre><code>if (myMap.has(someString)) { let val = myMap[someString]; // do something with val here } </code></pre> <p>Both ES6 features are now built into node.js as of node V4 (the current version of node.js as of this edit is v6).</p> <p>See <a href="https://jsperf.com/binary-search-versus-indexof-versus-hash-key-check/9" rel="nofollow noreferrer">this performance comparison</a> to see how much faster the <code>Set</code> operations are than many other choices.</p> <p><strong>Older Answer</strong></p> <p>All important performance questions should be tested with actual performance tests in a tool like jsperf.com. In your case, a javascript object uses a hash-table like implementation because without something that performs pretty well, the whole implementation would be slow since so much of javascript uses object.</p> <p>String keys on an object would be the first thing I'd test and would be my guess for the best performer. Since the internals of an object are implemented in native code, I'd expect this to be faster than your own hashtable or binary search implemented in javascript.</p> <p>But, as I started my answer with, you should really test your specific circumstance with the number and length of strings you are most concerned about in a tool like jsperf.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload