Is there any advantage to Array.prototype.includes() over Array.prototype.indexOf() depending on browsers (Chrome, Firefox) and needle item position (at the begging, middle, ending of the array)?
Array.prototype.includes vs. Array.prototype.indexOf
There is no browser specific information, there is no position in the array specific information, and I don’t ask about
I made a test using array with 10 000 numeric values, here is results:
- includes (22,043,904 ops/sec)
- indexOf (136,512,737 ops/sec)
- includes (8,361 ops/sec)
- indexOf (31,296 ops/sec)
- includes (4,018 ops/sec)
- indexOf (95,221 ops/sec)
- includes (34,087,623 ops/sec)
- indexOf (33,196,839 ops/sec)
- includes (84,880 ops/sec)
- indexOf (86,612 ops/sec)
- includes (25,253 ops/sec)
- indexOf (14,994 ops/sec)
indexOf() in Chrome works much faster than
includes() in all positions.
In Firefox both
includes() works almost similar.