【问题标题】:Returning results from multiple functions in JavaScript [duplicate]从JavaScript中的多个函数返回结果[重复]
【发布时间】:2017-11-19 17:26:42
【问题描述】:

我正在尝试返回 2 个函数的结果,但没有成功。我正在执行以下操作:

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

但是得到这个输出:

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

【问题讨论】:

    标签: javascript function return


    【解决方案1】:

    您可以使用数组作为两个函数的结果对象,例如

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

    或者对带有键的部分使用对象,例如

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

    【讨论】:

      猜你喜欢
      • 2019-07-31
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 2011-11-07
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      相关资源
      最近更新 更多