Identifies the element type of the array-like or iterable.
Identifies returned type of the array
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 value and its index (mapFn(value, index))
and the thisArg as this.
OptionalthisArg: any
Value of 'this' used to invoke the mapfn.
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"} ]
Creates an new shallow-copied array from an array-like object or an iterable.
It uses the native
Array.from()when it is available, otherwise polyArrFrom (see it for the differences). LikeArray.from()an iterator which is not iterable (eg. one created by createIterator or createRangeIterator, which has anext()function but no[Symbol.iterator]) returns an empty array, use iterToArray to read the values of an iterator.