jQ .length for exists

Benchmark created by Alex Sexton on


Description

$('.doesntexist')[0] is shorter than $('.doesntexist').length

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
.length
var i = 0;
if ( $('.doesntexist').length ) {
  i++;
}
ready
index
var i = 0;
if ( $('.doesntexist')[0] ) {
  i++;
}
ready

Revisions

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

  • Revision 1: published by Alex Sexton on