I want to count the wins and losses out of an array of matches but for some reason it doesn't work. In theory it should work but both output 0.
Here is my code I'm using handlebars so the {{ work!
const matches = [{
id: '9',
primary_player: 'player1',
secondary_player: 'player2',
size: '5',
result: '0'
}]
const losses = matches.filter(e => e.result == "0" && e.primary_player == "player1").length;
const wins = matches.filter(e => e.result == "1" && e.primary_player == "player1").length;
console.log(losses,wins)
It looks like the problem is just your double quotes wrapped around the primary_player check -- they're not needed in the evaluation. Also, I'm not sure that your length check at the end is useful in any way? Please do correct me, though, if you need it in there (and perhaps explain what you're trying to do with it).
Anyway, this should work (if your matches.result really is a boolean):
const losses = matches.filter(e => e.result === 0 && e.primary_player == user.nickname);
If matches.result is actually a string, which is the more probable data type, then you'll can drop the strict equality check (===):
const losses = matches.filter(e => e.result == 0 && e.primary_player == user.nickname);