-
Notifications
You must be signed in to change notification settings - Fork 0
Async Map
Sykander edited this page Jul 11, 2020
·
8 revisions
The asyncMap()
method creates a new array populated with the results of calling a provided async function on every element in the calling array.
let newArray = await asyncArray.asyncMap(
async function callback(currentValue[, index[, array]]) {
// return currentValue for newArray
}
[, thisArg]
);
-
callback
Async function that is called for every element ofasyncArray
. Each timecallback
executes, the returned value is added tonewArray
. It accepts between one and three arguments:-
currentValue
The current element being processed in the iterable object. -
index
|optional
The index ofcurrentValue
in the iterable object. -
array
|optional
The iterable object thatasyncFilter
was called upon.
-
-
thisArg
optional
Value to use asthis
when executingcallback
.
const { asyncFilter } = require('iterable-async'),
array = [1, 2, 3];
const found = await asyncMap(async element => {
return element + 2;
}, array);
console.log('Mapped new Array ', ...found);
// Mapped new Array 3, 4, 5
const { asyncFind } = require('iterable-async'),
array = [1, 2, 3,];
array.asyncMap = asyncMap;
const found = await array.asyncMap(async element => {
return element + 2;
});
console.log('Mapped new Array ', ...found);
// Mapped new Array 3, 4, 5