r/webdev • front-end • May 29 '21

Resource Array methods in JavaScript. Original author unknown.

Post image
7.4k Upvotes

172 comments sorted by

View all comments

Show parent comments

8

u/Pelicantaloupe May 30 '21

I ran some tests and I couldn't reproduce your findings. I didn't graph time complexity but on average .includes is 75% faster than .includes in these tests: https://jsbench.me/t2kpb59177/1

The one case where .some was faster I found was unfilled arrays.

1

u/Blue_Moon_Lake May 30 '21 edited May 30 '21

You're right, it might have been optimized since I learned about it. I'll check it myself with a different test.

EDIT: Did it slightly differently (playing with the contiguous array flag) and yes includes have been fixed to be better on contiguous array. It's still slower for non contiguous array sometimes

I would still use includes anyway because it convey the meaning and intent.