Why searching for the middle item in an array of 100 is faster than in an array of 10 items? [closed]
I made some tests to check this but is quite not expected: http://jsperf.com/value-in-array-or-object
You can run those tests too..
It's not faster. It appeared faster in your tests because you were assigning rather than comparing in the tests for 50 and 100 items:
if(a100[x] = 'item50'){
break;
}
The test with 10 items was correct:
if(a10[x] === 'item5'){
break;
}
See updated test cases here.
精彩评论