正在跳过Node.js代码(for)

时间:2015-07-13 14:35:33

标签: javascript node.js for-loop asynchronous

我看不到这里发生了什么,有人可以启发我吗?

为什么我不参加FOR? 代码:

console.log('l:269');

var smallestPrice = itemPriceAll; // start with max
console.log('itemNames.length, itemPriceall: ' + itemNames.length + ' ' + itemPriceAll);
for (var y; y < itemNames.length; y++) {
    console.log('Are you fucking kidding me?');
    console.log('l:272, itemPrice: ' + itemPrice[y] + 'houseEdge: ' + (itemPriceAll * houseEdge));
    if (itemPrice[y] >= (itemPriceAll * houseEdge)) {
        console.log('l:274');
        if (itemPrice[y] < smallestPrice) {
            smallestPrice = itemPrice[y]; 
            keeping = itemId[y]; 
        }
    }
}

console.log('l:284');

输出:

l:269
itemNames.length, itemPriceall 23 97
l:284

2 个答案:

答案 0 :(得分:1)

for循环中,您的条件为y < itemNames.length,但y的初始值为undefined。因此,这种情况是错误的。如果要进行数值比较,则应将y初始化为数值。

我建议var y = 0

答案 1 :(得分:0)

for(var y = 0; y < itemNames.length; y++)
是的;是的;我希望你是空的和数字的。

感谢https://stackoverflow.com/users/4265939/neilsimp1