⛄ 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
S
Sniberb688d 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,
}))
UU
Unknown User688d ago