Working on a NodeJS web app and am trying to get some information from my backend dataset. Here's what the pertinent part of the Mongoose model looks like:
gameLog: [
{
date: String,
season: String,
location: String,
opp: String,
gameType: String,
result: String,
start: Number,
min: Number,
fgm: Number,
fga: Number,
fgp: Number,
twoPM: Number,
twoPA: Number,
twoP: Number,
threePM: Number,
threePA: Number,
threeP: Number,
ftm: Number,
fta: Number,
ftp: Number,
orb: Number,
drb: Number,
ast: Number,
stl: Number,
blk: Number,
to: Number,
pf: Number,
pts: Number
}
]
It's for the storage of box scores. How can I search through each object's season
field and return an array containing the unique values from that field? When I use a map the searches the data of the requested player
on the route, it returns:
let seasons = foundPlayer.gameLog.map(({
season}) => season);
// Output
[
'2019', '2019', '2019', '2019', '2019',
'2019', '2019', '2019', '2019', '2019',
'2019', '2019', '2019', '2019', '2019',
'2019', '2019', '2019', '2019', '2019',
'2019', '2019', '2019', '2019', '2019',
'2019', '2020', '2020', '2020', '2020',
'2020', '2020', '2020', '2020', '2020',
'2020', '2020', '2020', '2020', '2020',
'2020', '2020', '2020', '2020', '2020',
'2020', '2020', '2020', '2020', '2020',
'2020', '2020', '2020', '2020', '2020',
'2020', '2020', '2020'
]
So rather than each instance of the season in the array, I want the unique values. What am I missing here? Thanks in advance for the help!