首页 > 解决方案 > Make function calls sequentially from a array of objects without waiting for result

问题描述

I have an array of objects. For all the objects inside that array, i have to execute a series of function and that result should be sent back to callee. I want to execute these functions for those objects sequentially or paralleled without waiting for the result.

for example: I have

const arr = [{...},{...},{...},...{...}];
function exeArr(obj) {
  function f1(){...},
  function f2(){...}
  return result
}

标签: javascript

解决方案


使用异步代码执行setTimeout

setTimeout(() => exeArr(obj), 0);
setTimeout(f1, 0);
setTimeout(f2, 0);
...

推荐阅读