need you help, I have this array in a "server" js file, than, with a service, is stored in a allplayers = []; I want to filter the array so only the jazz players will remain (in players = []; ) used the code below. have any idea why it does not work? thanks
var players = [
{team: 'bulls', fullName: 'Kerr', position: 'SG', ranking: '7', id: '1' },
{team: 'jazz',fullName: 'stockton', position: 'PG', ranking: '9', id: '2'},
{team: 'jazz',fullName: 'malone', position: 'PF', ranking: '8', id: '3'}
];
export class PlayersComponent implements OnInit {
players = [];
allplayers = [];
bullsPlayers = [];
constructor(private _playerService: PlayerService) {}
filterjazzplayers(){
for (let i = 0; i < this.allplayers.length; i++) {
if (this.allplayers[i].team == 'jazz') {
this.players.push(this.allplayers[i]);
}
}
}
ngOnInit (){
this._playerService.getPlayers()
.subscribe(
allplayers => this.allplayers = allplayers,
error => console.log(<any>error)
);
this.filterjazzplayers();
}