JavaScript performance: simple key search in object vs value search in array
<p>I need to emulate <a href="https://en.wikipedia.org/wiki/Set_%28mathematics%29" rel="nofollow">set</a> in JavaScript — i.e. variable that is able to answer question "do I contain <em>x</em>?".</p>

<p>Performance of insertion/deletion doesn't matter. Order doesn't matter. And it isn't <a href="https://en.wikipedia.org/wiki/Multiset" rel="nofollow">multiset</a>.</p>

<p>There are two  ways to implement it:</p>

<ol>
<li><p>Using regular array with value search:</p>

<pre><code>var set = [17, 22, 34];
if (set.indexOf(x)!=-1) ...;
</code></pre>

<ul>
<li><p>1a. Using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" rel="nofollow">TypedArray</a> (e.g. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array" rel="nofollow">Int32Array</a>), when possible:</p>

<pre><code>var set = Int32Array.of(17, 22, 34);
if (set.indexOf(x)!=-1) ...;
</code></pre></li>
</ul></li>
<li><p>Using object with key search:</p>

<pre><code>var set = {17: true, 22: true, 34: true};
if (set[x]) ...;
</code></pre></li>
</ol>

<p>Theoretically object key search should be much faster (depending on how they implemented it in JS engine, it should be either <em>O(log(n))</em>, or <em>O(1)</em> — vs <em>O(n)</em> on array value search). However, is this a case in JavaScript (where access to object member may require multiple lookups) — especially on small sets with dozens of items? Assuming that values in set are quite simple (either integers, or short strings).</p>

<p><strong>Resume.</strong> I want to know: what minimum amount of set items is required to make object key search faster than array value search in case of: (1) values are integers; (2) values are short strings — in modern (2015/2016) web-browsers?</p>

<p><sub>I understand that I can perform measurements myself, but it seems to be irrational to make every developer measure the same things — so I put this question here in case somebody have done it.</sub></p>