obj by key vs arr index of

Edit on GitHub

Setup

function range(start, end) {
    var foo = [];
    for (var i = start; i <= end; i++) {
        foo.push(i);
    }
    return foo;
}
obj = {}

arr.forEach(function(k) {obj[k] = true})

Tests

  • obj by key

    obj[999] === true
  • arr index of

    arr.indexOf(999) > -1