Users hate clutter. Duplicated items in a list? Confusing. Repeating options in a dropdown? Annoying. Clicking the same thing twice? Frustrating.
That’s why using something as simple as lodash.uniq
can make your app feel polished and intentional.
💡 What is lodash.uniq
?
lodash.uniq
is a tiny utility that removes duplicate values from an array.
import uniq from 'lodash.uniq'
uniq([1, 2, 2, 3, 1]) // → [1, 2, 3]
It looks basic, but its impact on UX is huge.
👀 Why should users care?
Because duplicated data feels like bugs.
Without uniq
:
- Dropdowns show the same item multiple times
- Filter tags get repeated
- Lists feel broken
- It’s harder to scan or choose
With uniq
:
✅ Clean options
✅ No confusion
✅ More trust in the app
🧪 Real-world use cases
1. 🛍 Filters in e-commerce
const categories = products.map(p => p.category)
// → ["Shoes", "Shoes", "Tops", "Shoes", "Tops"]
const unique = uniq(categories)
// → ["Shoes", "Tops"]
🟢 Users only see one option per category, not noise.
2. 🧾 Dropdowns and forms
const countries = users.map(u => u.country)
const options = uniq(countries).sort()
🟢 No one wants to scroll through “United States” three times.
3. 💬 Search suggestions
const terms = uniq(recentSearches)
🟢 Shows real, unique history — not clutter.
4. 📊 Charts / labels
const labels = uniq(data.map(d => d.label))
🟢 Prevents duplicate legends or x-axis labels.
🧠 What if i need unique by property?
Use uniqBy
:
import uniqBy from 'lodash.uniqby'
const items = [
{ id: 1, name: 'Apple' },
{ id: 1, name: 'Apple again' },
{ id: 2, name: 'Orange' }
]
uniqBy(items, 'id')
// → [{ id: 1, name: 'Apple' }, { id: 2, name: 'Orange' }]
🟢 Works great for deduplicating by IDs, emails, or keys.
✅ Should you use it?
Yes, if:
- You display lists or options from dynamic data
- You use
.map()
or.flatMap()
on untrusted sources - You want a clean UI and better experience
📎 Conclusions
Using lodash.uniq
isn’t about code — it’s about respecting your users' attention. Repeated data adds noise, slows decisions, and breaks flow.
Clean it up. Your users may not notice what’s missing — but they’ll feel the difference.