javascript foreach synchronous or asynchronous