Knowledgize

Array.from(arrayLike, mapFn, thisArg)

Creates a new Array instance from an array-like or iterable object, optionally mapping each item using a map function.

Examples:

let string = 'hello'; let letters = Array.from(string); console.log(letters); // ['h', 'e', 'l', 'l', 'o']
let set = new Set([1, 2, 3]); let numbers = Array.from(set); console.log(numbers); // [1, 2, 3] const numbers = [1, 2, 3]; const doubled = Array.from(numbers, x => x * 2); console.log(doubled); // [2, 4, 6]
// Array-like object const arrayLike = { 0: '10', 1: '20', 2: '30', length: 3 }; // Mapping function function mapFn(element) { return parseInt(element) * this.multiplier; } // Context object const context = { multiplier: 2 }; // Using Array.from directly const result = Array.from(arrayLike, mapFn, context); console.log(result); // [20, 40, 60]