Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Chrome 124
Mac OS X 10.15.7
Desktop
8 months ago
Test name Executions per second
array.find 605417.6 Ops/sec
array.filter 677150.8 Ops/sec
lodash.filter 529410.6 Ops/sec
HTML Preparation code:
AخA
 
1
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js">
2
</script>
3
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.29/angular.min.js"></script>
4
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js"></script>
5
<script>
6
  _lodash = _.noConflict();
7
</script>
8
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
Script Preparation code:
x
 
var angularFilter = angular.injector(['ng']).get('$filter')('filter');
// Generate test array
window.array = (function() {
  var arr = [];
  for (var i = 0; i < 100; ++i) {
    arr.push(i);
  }
  return arr;
}());
Array.prototype.find = function(predicate) {
  if (this == null) {
    throw new TypeError('Array.prototype.find called on null or undefined');
  }
  if (typeof predicate !== 'function') {
    throw new TypeError('predicate must be a function');
  }
  var list = Object(this);
  var length = list.length >>> 0;
  var thisArg = arguments[1];
  var value;
  for (var i = 0; i < length; i++) {
    value = list[i];
    if (predicate.call(thisArg, value, i, list)) {
      return value;
    }
  }
  return undefined;
};
function getValue(el) {
    return el - 50 > 31;
}
Tests:
  • array.find

     
    array.find(getValue);
  • array.filter

     
    array.filter(getValue);
  • lodash.filter

     
    _lodash.filter(array, getValue);