Move this inside the team.filter callback. In general, declare variables at the most inner scope possible. Otherwise it can lead to bugs/confusion later.