Test name | Executions per second |
---|---|
UniqBy | 2093831.4 Ops/sec |
Set | 3384272.8 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
const a = [{a:1},{a:1},{a:1},{a:2},{a:2},{a:3}]
const uniques = _.uniqBy(a, 'a')
const a = [{a:1},{a:1},{a:1},{a:2},{a:2},{a:3}]
const uniques = [];
const set = new Set();
for (const e of a) {
if(!set.has(e.a)) {
uniques.push(e);
set.add(e.a);
}
}