Remove multiple objects that contain a specific value from an array

Benchmark created on


Setup

const arr = [{ foo: 1 }, { foo: 2 }, { foo: 3 }, { foo: 4 }]

Test runner

Ready to run.

Testing in
TestOps/sec
forEach() + splice()
arr.forEach((item, index) => {
  if (item.foo === 2) {
  	arr.splice(index, 1)
  }
})
ready
filter()
arr.filter(item => item.foo !== 2)
ready

Revisions

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