Key exists check

JavaScript performance comparison

Revision 47 of this test case created

Preparation code

  var data = Object.create(null);
  var out = {};
  var toCheck;
  var toCheckNotExists;
  for (var i = 0; i < 10000; i++) {
   var key = 'user ' + i;
   data[key] =  key + i;

   // toCheck is initialized here to prevent any optimizations for static values
   if ( i == 5000) {
     toCheck = key;
     toCheckNotExists = "not" + key;

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
key in data
out[0] = toCheck in data;
out[1] = toCheckNotExists in data;
out[0] = data[toCheck] !== undefined;
out[1] = data[toCheckNotExists] !== undefined;

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:


Comment form temporarily disabled.

Add a comment