Creates an array from an array-like object.
interface
ArrayConstructor
interface ArrayConstructor
- constructor ArrayConstructor(arrayLength?: number): any[];constructor ArrayConstructor<T>(arrayLength: number): T[];constructor ArrayConstructor<T>(...items: T[]): T[];
- @param arrayLike
An array-like object to convert to an array.
arrayLike: ArrayLike<T>,mapfn: (v: T, k: number) => U,thisArg?: any): U[];Creates an array from an iterable object.
@param arrayLikeAn array-like object to convert to an array.
@param mapfnA mapping function to call on every element of the array.
@param thisArgValue of 'this' used to invoke the mapfn.
iterable: Iterable<T, any, any> | ArrayLike<T>): T[];Creates an array from an iterable object.
@param iterableAn iterable object to convert to an array.
iterable: Iterable<T, any, any> | ArrayLike<T>,mapfn: (v: T, k: number) => U,thisArg?: any): U[];Creates an array from an iterable object.
@param iterableAn iterable object to convert to an array.
@param mapfnA mapping function to call on every element of the array.
@param thisArgValue of 'this' used to invoke the mapfn.
- iterableOrArrayLike: AsyncIterable<T, any, any> | Iterable<T | PromiseLike<T>, any, any> | ArrayLike<T | PromiseLike<T>>): Promise<T[]>;
Creates an array from an async iterator or iterable object.
@param iterableOrArrayLikeAn async iterator or array-like object to convert to an array.
iterableOrArrayLike: AsyncIterable<T, any, any> | Iterable<T, any, any> | ArrayLike<T>,mapFn: (value: Awaited<T>, index: number) => U,thisArg?: any): Promise<Awaited<U>[]>;Creates an array from an async iterator or iterable object.
@param iterableOrArrayLikeAn async iterator or array-like object to convert to an array.
@param thisArgValue of 'this' used when executing mapfn.
arrayLike: AsyncIterable<T, any, any> | Iterable<T, any, any> | ArrayLike<T>): Promise<Awaited<T>[]>;Create an array from an iterable or async iterable object. Values from the iterable are awaited.
await Array.fromAsync([1]); // [1] await Array.fromAsync([Promise.resolve(1)]); // [1] await Array.fromAsync((async function*() { yield 1 })()); // [1]
@param arrayLikeThe iterable or async iterable to convert to an array.
@returnsA Promise whose fulfillment is a new Array instance containing the values from the iterator.
arrayLike: AsyncIterable<T, any, any> | Iterable<T, any, any> | ArrayLike<T>,mapFn?: (value: T, index: number) => U,thisArg?: any): Promise<Awaited<U>[]>;Create an array from an iterable or async iterable object. Values from the iterable are awaited. Results of the map function are also awaited.
await Array.fromAsync([1]); // [1] await Array.fromAsync([Promise.resolve(1)]); // [1] await Array.fromAsync((async function*() { yield 1 })()); // [1] await Array.fromAsync([1], (n) => n + 1); // [2] await Array.fromAsync([1], (n) => Promise.resolve(n + 1)); // [2]
@param arrayLikeThe iterable or async iterable to convert to an array.
@param mapFnA mapper function that transforms each element of
arrayLike
after awaiting them.@param thisArgThe
this
to whichmapFn
is bound.@returnsA Promise whose fulfillment is a new Array instance containing the values from the iterator.
- @param items
A set of elements to include in the new array object.