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 |
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
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;
}
_.forEach(array,fn)
array.forEach(fn)
for(let i = 0, l = array.length; i < l; ++i) fn(array[i]);
$.each(array, fn);
for (const item of array) fn(item);