如果函数的个数不知道,如何在asynchronous瀑布内迭代

我有一个节点js函数,它给了我数组的ID,使用这些ID我不得不从我的永久存储调用函数,每个函数将处理的值传递给其他,为此,我正在使用瀑布。

我需要将一个函数的值传递给另一个函数。

我正在使用它

var utilArray = utilityFunction(); var arrayofFunctions = []; for (var index = 0; index < utilArray.length; index++) { var functionToInsert = null; if (index == 0) { functionToInsert = function(callback) { id = testArray[index] //here index is set to length of utilArray when this is proccessed //function body callback(null, arg1); } } else { functionToInsert = function(arg1, callback) { id = testArray[index] //here also index is set to length of utilArray when this is proccessed //function body callback(null, arg1); } } functionArray.push(functionToInsert); } async.waterfall(functionArray, function(err, result) { console.log("entering result function pre"); if (err) { throw new Error(); } else { //process result } }); 

在这里,我的索引值变成了数组的长度,只是像这样应用。 如果utilArray的长度是3那么索引将是3,并将像这样应用,有没有办法我可以保留索引值,就像0,它应该是0,1应该是1。

或者还有其他的方法。