Function polyArrFrom

  • The polyArrFrom 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>

      A mapping function to call on every element of the array. If provided, every value to be added to the array is first passed through this map function, and the return value is added to the array instead. The function is called with the following arguments:

    • Optional thisArg: any

      Value of 'this' used to invoke the mapfn.

    Returns U[]

    Since

    0.9.7

    Example

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

    polyArrFrom(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"]
    ]);

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

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

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

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