Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript生成循环更改编号_Javascript - Fatal编程技术网

Javascript生成循环更改编号

Javascript生成循环更改编号,javascript,Javascript,我这里有一段代码: for(var i = 0; i < bots.length; i++){ if ( bots[i].getInventory().getItems().length < capacity ){ var executed = false; bots[i].createDeposit({ steamid: req.query.steamid,

我这里有一段代码:

    for(var i = 0; i < bots.length; i++){
        if ( bots[i].getInventory().getItems().length < capacity ){  
            var executed = false;
            bots[i].createDeposit({
                steamid: req.query.steamid,
                token: req.query.token,
                itemsFromThem: uniqueItems,
                message: req.query.message,
                callback: function( err, dbTradeId ){
                    if ( !executed ){
                        executed = true;
                        if ( !err && dbTradeId ){
                            res.json({ result: 1, dbTradeId: dbTradeId });   
                        } else {
                            console.log('» Tried to create deposit, but',err);
                            res.json({ error: err });                    
                        }
                    }
                }
            });
        } else {
            console.log('» Tried to create deposit, but no bot found(2)');
            return res.json({ error: 'Available bot not found(2)' });
        }
    }
for(变量i=0;i
问题是。我有
用于
循环,但是如果
但是机器人有足够的长度,我就不能通过
。如果一个失败了,它不会为其他人测试,如果是这样,有没有办法做到,如果一个失败了,它会尝试另一个,如果成功了,它就不会尝试


关于

返回
将打破else语句中的循环

尝试使用数组添加消息,然后在循环退出后调用该数组

差不多

var myMessages = [];
for(var i = 0; i < bots.length; i++){
    if ( bots[i].getInventory().getItems().length < capacity ){  
    // your code
    }else{
      myMessages.push("error": bot[i]);
    }
}
console.log(JSON.stringify( myMessages));
var myMessages=[];
对于(变量i=0;i