Check if object key exists

Benchmark created on


Description

This benchmark tries to find the fastest way of checking if a key exists in object using:

  • Object.keys includes
  • prop in object
  • object.hasOwnProperty

Setup

const obj = { foo: 'foo' }

Test runner

Ready to run.

Testing in
TestOps/sec
Object.keys includes
Object.keys(obj).includes('foo')
Object.keys(obj).includes('bar')
ready
prop in object
'foo' in obj
'bar' in obj
ready
object.hasOwnProperty
obj.hasOwnProperty('foo')
obj.hasOwnProperty('bar')
ready

Revisions

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