Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0
Firefox 131
Windows
Desktop
2 months ago
Test name Executions per second
_.compact 54662112.0 Ops/sec
filter(Boolean) 17806768.0 Ops/sec
filter(element => element) 45592396.0 Ops/sec
HTML Preparation code:
AخA
 
1
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
Script Preparation code:
 
var elements = [0, 1, false, 2, '', 3];
Tests:
  • _.compact

     
    _.compact(elements);
  • filter(Boolean)

     
    elements.filter(Boolean);
  • filter(element => element)

     
    elements.filter(element => element);