Find an element in an array (v2)

Revision 2 of this benchmark created on


Setup

const items = Array(100_000).fill(0).map((_, i) => ({id: i}))
const idx = items.length - 1

Test runner

Ready to run.

Testing in
TestOps/sec
Array.find
items.find(x => x.id == idx)
ready
for loop
for (let i = 0; i < items.length; i++) {
	if (items[i].id == idx) {
		return
	}
}
ready
for of loop
for (let item of items) {
	if (item.id == idx) {
		return
	}
}
ready
findIndex
items.findIndex(x => x.id == idx)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.