Test name | Executions per second |
---|---|
_.compact | 54662112.0 Ops/sec |
filter(Boolean) | 17806768.0 Ops/sec |
filter(element => element) | 45592396.0 Ops/sec |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
var elements = [0, 1, false, 2, '', 3];
_.compact(elements);
elements.filter(Boolean);
elements.filter(element => element);