Module: kongUtilArray

Functions in this file could be assigned to Array.prototype, and then you can use them as methods of an array. Assign what you want by yourself or call extendArrayPrototype() to add them all.

These functions are designed to run sequentially. If you want to run every async functions at the same time, consider static methods of Promise, such as all, any, race, and allSettled.

Note: to make this work, don't use arrow functions here.

Source:
Examples
// sequentially fetch resources and then resolves to responses.
    Array.prototype.mapAsync = kongUtilArray.mapAsync; // run once
    [url1, url2].mapAsync(fetch);
// same as above
    kongUtilArray.mapAsync(fetch, [url1, url2])

Methods

(inner) everyAsync(callback, targetopt) → {Promise.<boolean>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
Source:
Returns:
Type
Promise.<boolean>

(inner) extendArrayPrototype()

Add methods in this file to Array class.

Source:

(inner) filterAsync(callback, targetopt) → {Promise.<Array>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
Source:
Returns:
Type
Promise.<Array>

(inner) findAsync(callback, targetopt, returnIndexopt) → {Promise.<*>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
returnIndex boolean <optional>
false
Source:
Returns:
Type
Promise.<*>

(inner) findIndexAsync(callback, targetopt) → {Promise.<integer>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
Source:
Returns:
Type
Promise.<integer>

(inner) findLastAsync(callback, targetopt, returnIndexopt) → {Promise.<*>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
returnIndex boolean <optional>
false
Source:
Returns:
Type
Promise.<*>

(inner) findLastIndexAsync(callback, targetopt) → {Promise.<integer>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
Source:
Returns:
Type
Promise.<integer>

(inner) forEachAsync(callback, targetopt) → {Promise.<undefined>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
Source:
Returns:
Type
Promise.<undefined>

(inner) mapAsync(callback, targetopt, skipReturnopt) → {Promise.<Array>}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
skipReturn boolean <optional>
false
Source:
Returns:
Type
Promise.<Array>

(inner) mapToObject(callback, targetopt) → {Object}

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
Source:
Returns:

keys are the values of the array; values are what callback returns on each element.

Type
Object

(inner) reduceAsync(callback, initial, targetopt) → {Promise.<*>}

Parameters:
Name Type Attributes Default Description
callback function
initial *
target Array <optional>
this
Source:
Returns:
Type
Promise.<*>

(inner) reduceRightAsync(callback, initial, targetopt) → {Promise.<*>}

Parameters:
Name Type Attributes Default Description
callback function
initial *
target Array <optional>
this
Source:
Returns:
Type
Promise.<*>

(inner) shuffle(targetopt) → {Array}

randomize the order of the array in place

Parameters:
Name Type Attributes Default Description
target Array <optional>
this
Source:
See:
Returns:
Type
Array

(inner) someAsync(callback, targetopt)

Parameters:
Name Type Attributes Default Description
callback function
target Array <optional>
this
Source: