Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Chrome 114
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Set from array 1399647.9 Ops/sec
Filter 1801104.0 Ops/sec
Script Preparation code:
AخA
 
var array = Array.from({length: 40}, () => Math.floor(Math.random() * 140));
Tests:
  • Set from array

     
    const a = new Set(array)
  • Filter

     
    const filterUnique = (value, index, array) => array.indexOf(value) === index;
    const b = array.filter(filterUnique)