@nevware21/ts-utils
    Preparing search index...

    Function arrFrom

    • 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.

      • OptionalmapFn: 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:

      • OptionalthisArg: any

        Value of 'this' used to invoke the mapfn.

      Returns U[]

      0.9.7

      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"} ]