JavaScriptArrayArray.from

Creates a new array from an array-like or iterable object.

문법

Array.from(arrayLike, mapFn?)

예제

아래 값을 입력하면 예제에 즉시 반영됩니다.

const
str
chars
console
doubled
const str = "hello";
const chars = Array.from(str);
console.log(chars);   // ["h", "e", "l", "l", "o"]

const doubled = Array.from([1, 2, 3], (x) => x * 2);
console.log(doubled);   // [2, 4, 6]