Bun

interface

ArrayConstructor

interface ArrayConstructor

  • constructor ArrayConstructor(
    arrayLength?: number
    ): any[];
    constructor ArrayConstructor<T>(
    arrayLength: number
    ): T[];
    constructor ArrayConstructor<T>(
    ...items: T[]
    ): T[];
  • readonly prototype: any[]
  • from<T>(
    arrayLike: ArrayLike<T>
    ): T[];

    Creates an array from an array-like object.

    @param arrayLike

    An array-like object to convert to an array.

    from<T, U>(
    arrayLike: ArrayLike<T>,
    mapfn: (v: T, k: number) => U,
    thisArg?: any
    ): U[];

    Creates an array from an iterable object.

    @param arrayLike

    An array-like object to convert to an array.

    @param mapfn

    A mapping function to call on every element of the array.

    @param thisArg

    Value of 'this' used to invoke the mapfn.

    from<T>(
    iterable: Iterable<T, any, any> | ArrayLike<T>
    ): T[];

    Creates an array from an iterable object.

    @param iterable

    An iterable object to convert to an array.

    from<T, U>(
    iterable: Iterable<T, any, any> | ArrayLike<T>,
    mapfn: (v: T, k: number) => U,
    thisArg?: any
    ): U[];

    Creates an array from an iterable object.

    @param iterable

    An iterable object to convert to an array.

    @param mapfn

    A mapping function to call on every element of the array.

    @param thisArg

    Value 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 iterableOrArrayLike

    An async iterator or array-like object to convert to an array.

    fromAsync<T, U>(
    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 iterableOrArrayLike

    An async iterator or array-like object to convert to an array.

    @param thisArg

    Value 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 arrayLike

    The iterable or async iterable to convert to an array.

    @returns

    A Promise whose fulfillment is a new Array instance containing the values from the iterator.

    fromAsync<T, U>(
    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 arrayLike

    The iterable or async iterable to convert to an array.

    @param mapFn

    A mapper function that transforms each element of arrayLike after awaiting them.

    @param thisArg

    The this to which mapFn is bound.

    @returns

    A Promise whose fulfillment is a new Array instance containing the values from the iterator.

  • arg: any
    ): arg is any[];
  • of<T>(
    ...items: T[]
    ): T[];

    Returns a new array from a set of elements.

    @param items

    A set of elements to include in the new array object.