Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36
Chrome 96
Mac OS X 10.15.7
Desktop
3 years ago
Test name Executions per second
filter 3694519.0 Ops/sec
forEach 2513979.0 Ops/sec
Script Preparation code:
x
 
var arr = [];
for(i=0; i<100; i++){
  Math.random() > .5 ? arr.push({is_group: true}) : arr.push({is_group: false})
}
Tests:
  • filter

     
    const a = arr.filter(i => i.is_group)
  • forEach

     
    const a = [];
    const b = [];
    arr.forEach(i => {
      if (i.is_group) {
        a.push(i)
      } else {
        b.push(i)
      }
    })