Skip to content

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 function on every element in the calling array.

Syntax

asyncArr.asyncMap(callback(currentValue[, index[, array]])[, thisArg])

Examples

As a function

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

As a method

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
Clone this wiki locally