Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36
Chrome 86
Mac OS X 10.14.6
Desktop
4 years ago
Test name Executions per second
lodash.each 76563.2 Ops/sec
native 71734.4 Ops/sec
for loop 7960.0 Ops/sec
jQuery each 51109.9 Ops/sec
for..of loop 15356.8 Ops/sec
HTML Preparation code:
AخA
 
1
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
Script Preparation code:
x
 
var array = new Array(1000);
for (let i = 0, l = array.length; i < l; ++i) array[i] = i;
function fn (item) {
  return item * 2 * 5;
}
      
Tests:
  • lodash.each

     
    _.forEach(array,fn)
  • native

     
    array.forEach(fn)
  • for loop

     
    for(let i = 0, l = array.length; i < l; ++i) fn(array[i]);
  • jQuery each

     
    $.each(array, fn);
  • for..of loop

     
    for (const item of array) fn(item);