javascript - Quickest way to check if a number is in a set? -


what fastest method check if number in list in javascript?

i know indexof >= seems rather slow me.

i have perform millions of checks per second , list rather short (max ~10 entries)

try out @ jsperf suspect using object , setting numbers properties faster array search.

var thelist = { 1: true, 2000: true, 253: true, -12077: true, ... };  if (thelist[ somenumber ]) { // see if number in list 

now, said, you're not going able useful in javascript in web browser millions of times per second, except perhaps on extremely high-end machines aren't doing else.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -