Editing in Object vs Array.indexOf This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Is it faster to look up the existence of a key on an object or the existence of an item in an array. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { "use strict"; if (this == null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (len === 0) { return -1; } var n = 0; if (arguments.length > 1) { n = Number(arguments[1]); if (n != n) { // shortcut for verifying if it's NaN n = 0; } else if (n != 0 && n != Infinity && n != -Infinity) { n = (n > 0 || -1) * Math.floor(Math.abs(n)); } } if (n >= len) { return -1; } var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); for (; k < len; k++) { if (k in t && t[k] === searchElement) { return k; } } return -1; } } var obj = {}, arr = []; for(var i = 0; i < 1000; i++) { if(i % 2 === 0) { arr.push(obj[i] = true); } } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code var count = 0; for(var i = 0; i < 1000; i++) { if(i in obj) { count++; } } Test 2 Title Async (check if this is an asynchronous test) Code var count = 0; for(var i = 0; i < 1000; i++) { if(arr.indexOf(i) > -1) { count++; } } Test 3 Title Async (check if this is an asynchronous test) Code var count = 0; for(var i = 0; i < 1000; i++) { if(obj[i] !== undefined) { count++; } } Test 4 Title Async (check if this is an asynchronous test) Code var count = 0; for(var i = 0; i < 1000; i++) { if(obj.hasOwnProperty(i)) { count++; } }