Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
teechap
· 11y ago · 0 comments
Linear definitely isn't faster than binary search. To answer your original question, .indexOf is definitely implemented as linear search in JavaScript
Comments
[–]
Demiurge
11y ago
Ok, it makes sense to me now. indexOf is used on mostly unsorted things, like strings. So, I guess the original problem might use a sorted array, or an object instead of an array, since I think the object keys are sorted and looked up pretty fast.