Sniberb
Sniberb3y ago

⛄ Snowberb ⛄ – 12-19 May 31

What's the best way to filter unique values from an array of objects? for example from this array, [{value: 'a', label: 'A'}, {value: 'b', label: 'B'}, {value: 'a', label: 'C'}, {value: 'c', label: 'C'}], I want the unique objects comparing the value prop
2 Replies
Sniberb
Sniberb3y ago
This is what I've done so far
const houses = bonuses.map((bonus) => ({ value: bonus.bookie, label: bonus.bookie }))
const uniqueHouses = Array.from(new Set(houses.map((bonus) => bonus.value))).map((bookie) =>
bonuses.find((bonus) => bonus.bookie === bookie)
)
const houses = bonuses.map((bonus) => ({ value: bonus.bookie, label: bonus.bookie }))
const uniqueHouses = Array.from(new Set(houses.map((bonus) => bonus.value))).map((bookie) =>
bonuses.find((bonus) => bonus.bookie === bookie)
)
Which is the same as
const uniqueHouses = Array.from(
new Set(
bonuses
.map((bonus) => ({ value: bonus.bookie, label: bonus.bookie }))
.map((bonus) => bonus.value)
)
).map((bookie) => bonuses.find((bonus) => bonus.bookie === bookie))
const uniqueHouses = Array.from(
new Set(
bonuses
.map((bonus) => ({ value: bonus.bookie, label: bonus.bookie }))
.map((bonus) => bonus.value)
)
).map((bookie) => bonuses.find((bonus) => bonus.bookie === bookie))
!close nah man im dumb I need to rest This is what I wanted:
const houses = Array.from(new Set(bonuses.map((bonus) => bonus.bookie))).map((bookie) => ({
value: bookie,
label: bookie,
}))
const houses = Array.from(new Set(bonuses.map((bonus) => bonus.bookie))).map((bookie) => ({
value: bookie,
label: bookie,
}))
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/981170008396824647