Я хочу установить команды
opponent = search_abbreviation
- это массив командных объектов, которые до l oop выглядят так:
var team = {
teamId: team_id,
teamAbbreviation: abbreviation,
gamePlayedId: game_id,
totalPlaysFor: offensePlays,
totalYardsFor: offenseYds,
yardsPerPlayFor: offenseAvgYds,
opponent: '',
totalPlaysAgainst: 0,
totalYardsAgainst: 0,
yardsPerPlayAgainst: 0
};
У меня есть следующее код, чтобы найти противника, сопоставляя gamePlayedId друг с другом, затем он обновит защитную (против) статистику и свойства противника. Что я делаю неправильно, что не позволяет мне изменять свойство оппонента?
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)