我的问题是知道是否可以使用异步方法与 lodash (sumBy) 值求和:
const Total = _.sumBy(taxes, t => asyncMethodExample(t.amount));
最佳答案
不可能这样使用它。 _.sumBy期望第二个参数返回要求和的值,而不是 Promise。
你可以这样做:
const total = _.sum(await Promise.all(taxes.map(t => asyncMethodExample(t.amount))));
关于javascript - 可以通过异步方法使用 _.sumBy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57615055/