I have an array of data that queries the results through a prop. I am able to obtain the data but, unable to sort it. I want all the data with MyTeam to appear first.
However, when I load this into the browser I obtain different results.
In Safari the data lists MyTeam to be the second element in the array
In Chrome, the data lists MyTeam to be the third element but, whenever I interact with them (via an onClick method) the data swaps around in a different order.
If I don't have the .sort() method, everything remains the same and nothing changes.
Is there a proper way to sort the array?
var gameList = this.props.data.sort(function(game) {
return (game.homeTeam == 'MyTeam' || game.awayTeam == 'MyTeam') ? 0 : 1;
}).map(function(game, i) {
//console.log(game.homeTeam + ' ' + game.awayTeam);
});