R
Reactiflux

⛄ Snowberb ⛄ – 12-19 May 31

⛄ Snowberb ⛄ – 12-19 May 31

S⛄Snowberb⛄5/31/2022
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 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,
}))
UUUnknown User6/1/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

⛄ Snowberb ⛄ – 12-19 May 31

Join Server