Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0
Chrome 126
Windows
Desktop
9 months ago
Test name Executions per second
Lodash uniqBy 3437.6 Ops/sec
Custom uniq array 823.6 Ops/sec
HTML Preparation code:
AخA
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
x
 
var myArr = Array.from({
    length: 16000
}, () => ({ value: Math.floor(Math.random() * 1000) }));
var myCopy = null;
Tests:
  • Lodash uniqBy

     
    myCopy = _.uniqBy(myArr, 'value');
  • Custom uniq array

     
    const itemIdSet = new Set(myArr.map(item => item.value));
    const uniqueItems = [];
    itemIdSet.forEach(value => {
        const uniqueItem = myArr.find(item => item.value === value);
        if (uniqueItem) uniqueItems.push(uniqueItem);
    });
    myCopy = uniqueItems;