Reputation: 5845
I am trying to filter an array as I have a million times in the past but it's not working.
locations = city.locations.filter(
(l) => {
console.log(l._id);
console.log(req.query.locationId);
console.log(l._id === req.query.location);
return l._id === req.query.location;
}
)
Console output:
l1dr2jmg42lb2sgiudi
l1dr2jmg42lb2sgiudi
false
The first two console.log
print identical strings but the third prints false??!?
I checked that city.locations
is an Array
and both l._id
and req.query.locationId
are a string
.
Upvotes: 0
Views: 1166
Reputation: 363
console.log(l._id === req.query.location);
you are not referring to req.query.locationId
but toreq.query.location
. Missing Id
.
Upvotes: 3