for each with index

Benchmark created on


Setup

const obj = {}
let i = 10_000
while(i--){
	obj['a'+i] = i*2
}
const arr = []

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
Object.keys(obj).forEach((key,index)=>{
	if(index % 2){
		arr.push(key)
	}
})
ready
for..of Object.keys
let index = 0
for(const key of Object.keys(obj)){
	if(index % 2){
		arr.push(key)
	}
	index++
}
ready
for..in obj
let index = 0
for(const key in obj){
	if(index % 2){
		arr.push(key)
	}
	index++
}
ready

Revisions

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