array diff

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
  a = [1,2,3,4,5,6];
  b = [4,5,6,7,8];
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery
    remove = $.grep(a, function (el) {
      return $.inArray(el, b) === -1;
    });
ready
array filter
    remove = a.filter(function (el) {
      return b.indexOf(el) === -1;
    });
ready
array filter fancy
    remove = a.filter(function (el) {
      return !~b.indexOf(el);
    });
ready

Revisions

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