HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var myArr = Array.from({
    length: 16000
}, () => ({ value: Math.floor(Math.random() * 1000) }));
var myCopy = null;
Tests:
  • Lodash uniqBy

     
    myCopy = _.uniqBy(myArr, 'value').map(({ value }) => value);
  • new Set() Destructuring

     
    myCopy = [...new Set(myArr.map(({ value }) => value))]
  • uniq for loop

     
    var seen = {};
    var out = [];
    const len = myArr.length;
    var j = 0;
    for (var i = 0; i < len; i += 1) {
        var item = myArr[i].value;
      if (seen[item] !== 1) {
        seen[item] = 1;
        out[j++] = item;
      }
    }
    myCopy = out;
  • uniq by forEach

     
    var result = [];
    myArr.forEach((item) => {
        if (result.indexOf(item.value) < 0) {
            result.push(item.value);
        }
    });
    myCopy = result;
  • uniq by filter

     
    var mapMyArr = myArr.map(({ value }) => value);
    myCopy = mapMyArr.filter((value, index, array) => array.indexOf(value) === index);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lodash uniqBy
    new Set() Destructuring
    uniq for loop
    uniq by forEach
    uniq by filter

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0
Chrome 133 on Windows
View result in a separate tab
Test name Executions per second
Lodash uniqBy 5564.6 Ops/sec
new Set() Destructuring 3309.5 Ops/sec
uniq for loop 19750.3 Ops/sec
uniq by forEach 1018.5 Ops/sec
uniq by filter 607.0 Ops/sec