循環GET方法,例如:的NodeJS調用中使用我使用的NodeJS和Express和遍歷字符串數組回調
[ "1" , "+" , "B4", "*", "8"]
如果字符串包含一個字母,功能將會熄滅,通話一個GET方法從數據庫中檢索一個值。到目前爲止我的代碼看起來是這樣的:
function processFormula(formula) {
console.log(formula)
var arr = formula.split(" ");
for (var i = 0; i < arr.length; i++) {
if (arr[i].match(/[a-z]/i)) {
/* fetch the value and store it in arr[i] */
}
return arr.toString();
}
我的問題是,它熄滅來獲取值的方法花費的時間比處理線程來執行,導致
undefined
種植了很多。我正在努力瞭解我應該如何將我的回調反覆處理這種情況?
任何幫助,非常感謝!
看看第一個問題在這裏開始:http://stackoverflow.com/questions/tagged/javascript?sort=frequent。關於循環,看看其中的一個:http://stackoverflow.com/search?q=%5Bjavascript%5D+asynchronous+loop –
感謝Felix的幫助 –