2017-06-16 48 views
-1

我試圖返回2個函數的結果,但我沒有成功。我做了以下情況:在JavaScript中返回多個函數的結果

var x = getFunctionResults1(items); 
var y = getFunctionResults2(items); 
return {x,y} 

但是,讓這樣的輸出:

[ { x: [ [Object], [Object], [Object], [Object], [Object] ], 
    y: [ [Object] ] }, 
    { x: [ [Object], [Object] ], y: [ [Object] ] } ] 

回答

1

你可以使用一個數組作爲結果對象有兩個功能,如

return [getFunctionResults1(functionResults1), getFunctionResults2(functionResults2)]; 

或使用對象帶鑰匙的零件,如

return { 
    result1: getFunctionResults1(functionResults1), 
    result2: getFunctionResults2(functionResults2)] 
};