Fairly new to Javascript as I'm working on my first app, I am coming over from R where though data manipulations (with dplyr or even base R) become very easy, but I am struggling with this currently. I have the following data:
var teamsA = ['team1', 'team2', 'team3'];
var teamsB = ['team4', 'team5', 'team6'];
var teamgroup = A;
var myData = [
{player: "Joe", team: "team1"},
{player: "Tom", team: "team3"},
{player: "Red", team: "team2"},
{player: "Smi", team: "team5"},
{player: "Bib", team: "team6"},
{player: "Cat", team: "team2"},
{player: "Dan", team: "team3"},
{player: "Jim", team: "team1"}
]
With the data shown, the question is fairly simple: I would like to filter myData based on the team existing in whichever array is determined by the teamgroup variable. ie:
if(teamgroup == "A") {
myData.filter(team in teamsA)
} else {
myData.filter(team in teamsB)
}
...not quite sure how to do so with javascript. Prefer to use the new ES6 stuff. Thanks!
Aand the two variablesteamsAandteamsB? wound an object with propertiesAandBfit better for the selection for filtering?