Nodejs V8.11.2 .foreach Not A Function Error
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.pla
Solution 1:
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];
}
Post a Comment for "Nodejs V8.11.2 .foreach Not A Function Error"