Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Chrome 116
Windows
Desktop
one year ago
Test name Executions per second
Set spread 1386231.6 Ops/sec
Array from set 1236415.1 Ops/sec
Filter 361293.4 Ops/sec
filter 2 1420829.8 Ops/sec
includes 1541594.8 Ops/sec
Script Preparation code:
AخA
 
var array = Array.from({length: 40}, () => Math.floor(Math.random() * 140));
Tests:
  • Set spread

     
    const f = [... new Set(array)]
  • Array from set

     
    const s = new Set(array)
    const l = Array.from(s)
  • Filter

     
    const b = array.filter((i,index) => array.indexOf(i)=== index)
  • filter 2

     
    const b2 = array.filter((i,index, arr) => arr.indexOf(i)=== index)
  • includes

     
    var ar2 = [];
    array.forEach(i => {
        if (!ar2.includes(i)) {
          ar2.push(i);
        }
    });