filter + map vs conditional + foreach

Compare chained `array.filter().map()` vs creating a new array, looping through the previous one and conditionally pushing to it.
9 months ago
User agent: Mozilla/5.0 (Android 4.4.2; Tablet; rv:68.0) Gecko/68.0 Firefox/68.0
Test name Executions per second
filter + map 13143.1 Ops/sec
conditional + forEach 26356.2 Ops/sec
Script Preparation code:
  • filter + map

  • conditional + forEach

Open this result on