I am looking to set the
opponent = search_abbreviation
teams is an array of team objects that, before the loop, look like:
var team = {
teamId: team_id,
teamAbbreviation: abbreviation,
gamePlayedId: game_id,
totalPlaysFor: offensePlays,
totalYardsFor: offenseYds,
yardsPerPlayFor: offenseAvgYds,
opponent: '',
totalPlaysAgainst: 0,
totalYardsAgainst: 0,
yardsPerPlayAgainst: 0
};
I have the following code to find the opponent by matching the gamePlayedId's to each other, then it will update the defensive(against) stats and the opponent properties. What am I doing wrong that will not allow me to modify the opponent property?
var teams = [
{
teamId: 0,
teamAbbreviation: 'abbreviation1',
gamePlayedId: 11,
totalPlaysFor: 12,
totalYardsFor: 13,
yardsPerPlayFor: 14,
opponent: 'op',
totalPlaysAgainst: 0,
totalYardsAgainst: 0,
yardsPerPlayAgainst: 0
},
{
teamId: 1,
teamAbbreviation: 'abbreviation2',
gamePlayedId: 11,
totalPlaysFor: 12,
totalYardsFor: 13,
yardsPerPlayFor: 14,
opponent: 'op2',
totalPlaysAgainst: 0,
totalYardsAgainst: 0,
yardsPerPlayAgainst: 0
}];
const result = teams.forEach(({ teamAbbreviation, gamePlayedId, teamId }) => {
var search_gamePlayedId = gamePlayedId;
var search_teamId = teamId;
var search_abbreviation = teamAbbreviation;
teams.forEach(({ opponent, gamePlayedId, teamId }) => {
if (search_gamePlayedId === gamePlayedId && search_teamId !== teamId) {
opponent = search_abbreviation;
// Modify more properties
}
});
});
console.log(result)