Skip to content

map

使用异步函数映射数组

124 bytes
since v12.1.0

使用方法

map 函数类似于 Array.prototype.map,但它适用于异步函数。一次只处理一个项目。

const userIds = [1, 2, 3, 4];
const api = {
users: {
find: async (id: number) => id < 3,
},
};
const users = await _.map(userIds, async (userId) => {
return await api.users.find(userId);
}); // [true, true, false, false]