Aysnc forEachOf无法读取属性

时间:2017-06-17 13:34:26

标签: javascript node.js

有人能告诉我为什么会出现这样的错误:

当self.player为空且我添加新项目时,一切正常,当有人将第二项添加到数组时,接下来我想添加第三项,然后返回如下所示的错误。

  

TypeError:无法读取未定义的属性“profile”       at async.forEachOf.self.players.push.profile(/home/backend/index.js:1976:29)

我的代码如下:

console.log(self.players);
            async.forEachOf(self.players, function(value, key, callback) {
                if(value.profile.steamid.toString() == player.steamid.toString()){
                    itemsHashMarket.push(value.items[0]);    
                    //amount = parseInt(amount) + parseInt(value.bet);
                    self.players.splice(key, 1);
                }
                callback();
             }, function() {

                self.players.push({ profile: player, bet: amount, items: itemsHashMarket, percent: self._playerPercent, total: self._cash}); 


                return callback(null, {timeleft: self._timeLeft, players: [{ profile: player, bet: amount, items: itemsHashMarket, percent: self._playerPercent, total: self._cash}], hash: self._hash, percent: self._playerPercent, cash: self._cash, countitems:self._countItems}); // Broadcast newPlayer
            });

包含2个元素的self.player: enter image description here

0 个答案:

没有答案