Find Array Value

JavaScript performance comparison

Test case created by Soulcyon

Preparation code

<script>
  var validChars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
      checkFor = 'x';
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
For Loop
for (i = 0; i < validChars.length; i++)
if (validChars[i] == checkFor) return i;
pending…
For Loop 2
for (i in validChars)
if (validChars[i] == checkFor) return i;
pending…
IndexOf
return validChars.join("").indexOf(checkFor);
pending…
IndexOf 2
return validChars.indexOf(checkFor);
pending…
While Loop
i = validChars.length;
while( i-- )
  if( validChars[i] == checkFor ) return i;
pending…

Compare results of other browsers

Revisions

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:

0 comments

Add a comment