Reputation: 91
I'm trying to add a nodejs app we have on dev to production server. I'm getting this error when I run the script.
TypeError: team.player.forEach is not a function
I know team.player is legit. I console log it and it shows this.
player:
{ name: 'TEAM',
shortname: 'TEAM',
checkname: 'TEAM',
uni: 'TM',
class: 'FR',
gp: '1',
code: '198',
rush: { att: '0', yds: '465', gain: '465', loss: '0', td: '0', long: '0' },
pass:
{ comp: '0',
att: '0',
int: '0',
yds: '40',
td: '0',
long: '0',
sacks: '0',
sackyds: '0' },
fumbles: { no: '3', lost: '1' } }
The only thing I can figure out is that on the dev server we use v8.9.4 and this version on production we use 8.11.2 though I don't think that should matter in this instance and haven't heard of anyone else having this issue.
Upvotes: 0
Views: 1283
Reputation: 14788
Looks like player
is an object not an array. If You want to iterate over it, you should use Object.values
, Object.keys
, or Object.entries
:
Object.values(team.player).forEach(value => {
});
Object.keys(team.player).forEach(key => {
});
Object.entries(team.player).forEach(([key, value]) => {
});
Or a for...in
loop:
for(let key in team.player) {
if(!team.player.hasOwnProperty(key)) continue;
const value = team.player[key];
}
Upvotes: 3