Is value in set of acceptable values

Benchmark created by Matt Hamann on


Setup

var arrayValues = ['apple', 'banana', 'orange'];
    var objValues = {'apple': true, 'banana': true, 'orange': true}
    var checkValue = 'banana';
    var result;

Test runner

Ready to run.

Testing in
TestOps/sec
Array
arrayValues.indexOf(checkValue) > -1;
ready
Object
objValues[checkValue] === true;
ready
OR clause
(checkValue === 'apple' || checkValue === 'banana' || checkValue === 'orange');
ready

Revisions

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

  • Revision 1: published by Matt Hamann on