• Creates an new shallow-copied array from an array-like object or an iterable.

    Type Parameters

    • T

      Identifies the element type of the array-like or iterable.

    • U = T

      Identifies returned type of the array

    Parameters

    • theValue: ArrayLike<T> | Iterable<T>

      An array-like object or iterable to convert to an array.

    • Optional mapFn: ArrFromMapFn<T, U>
    • Optional thisArg: any

      Value of 'this' used to invoke the mapfn.

    Returns U[]

    Since

    0.9.7

    Example

    arrFrom("Hello");
    // [ "H", "e", "l", "l", "o" ]

    arrFrom(new Set(["Hello", "Darkness", "my", "old", "friend"]));
    // ["Hello", "Darkness", "my", "old", "friend"]

    let map = new Map([
    [ 1, "Hello" ],
    [ 2, "Darkness" ],
    [ 3, "my" ],
    [ 4, "old" ],
    [ 5, "friend"]
    ]);

    arrFrom(map.values());
    // ["Hello", "Darkness", "my", "old", "friend"]

    arrFrom(map.keys());
    // [ 1, 2, 3, 4, 5 ]

    arrFrom(map.entries());
    // [ [ 1, "Hello" ], [ 2, "Darkness" ], [ 3, "my" ], [ 4, "old" ], [ 5, "friend"] ]

    // With a Mapping function
    const map = new Map([
    [ 1, "Hello" ],
    [ 2, "Darkness" ],
    [ 3, "my" ],
    [ 4, "old" ],
    [ 5, "friend"]
    ]);

    arrFrom(map, ([ key, value ]) => ({ [key]: value }));
    // [ {"1": "Hello"}, {"2": "Darkness"}, {"3": "my"}, {"4": "old"}, {"5": "friend"} ]