Skip to main content

forEach

Functions​

forEach()​

forEach<T>(arrayOrPromise, callbackfn): Promise<void>

Calls a defined callback function on each element of an array.

Type Parameters​

Type ParameterDescription
TThe type of the elements in the array.

Parameters​

ParameterTypeDescription
arrayOrPromiseT[] | Promise<T[]>The array or Promise of an array to iterate over.
callbackfn(value, index, array) => unknownA function that accepts up to three arguments. The forEach method calls the callbackfn function one time for each element in the array.

Returns​

Promise<void>

A Promise that resolves when the loop is finished.

Remarks​

Calls a defined callback function on each element of an array. The forEach method calls the callbackfn function one time for each element in the array.

Example​

const array = [1, 2, 3, 4];
await forEach(array, (value) => console.log(value));
// Output:
// 1
// 2
// 3
// 4

Defined in​

src/forEach/index.ts:27