| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/from | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 9.
console.log(Array.from("foo"));
// Expected output: Array ["f", "o", "o"]
console.log(Array.from([1, 2, 3], (x) => x + x));
// Expected output: Array [2, 4, 6]
Array.from(arrayLike)
Array.from(arrayLike, mapFn)
Array.from(arrayLike, mapFn, thisArg)
arrayLike.
mapFnOptional . , mapFn . .
thisArgOptionalmapFn this .
Array .
Array.from() Array .
( , ) Object.keys(), Object.values(), Object.entries() . Array.fromAsync() .
Array.from() . arrayLike , undefined .
Array.from() map() mapFn . , Array.from(obj, mapFn, thisArg) (element, index) Array.from(obj).map(mapFn, thisArg) .
:
, . Array.from() TypedArray.from() .
Array.from() . , Array from() , from() Array . this . arrayLike , length . length . this , Array .
Array.from("foo");
// [ "f", "o", "o" ]
const set = new Set(["foo", "bar", "baz", "foo"]);
Array.from(set);
// [ "foo", "bar", "baz" ]
const map = new Map([
[1, 2],
[2, 4],
[4, 8],
]);
Array.from(map);
// [[1, 2], [2, 4], [4, 8]]
const mapper = new Map([
["1", "a"],
["2", "b"],
]);
Array.from(mapper.values());
// ['a', 'b'];
Array.from(mapper.keys());
// ['1', '2'];
// DOM
const images = document.querySelectorAll("img");
const sources = Array.from(images, (image) => image.src);
const insecureSources = sources.filter((link) => link.startsWith("http://"));
function f() {
return Array.from(arguments);
}
f(1, 2, 3);
// [ 1, 2, 3 ]
// map
Array.from([1, 2, 3], (x) => x + x);
// [2, 4, 6]
//
// `undefined`
// 'v' `undefined` .
Array.from({ length: 5 }, (v, i) => i);
// [0, 1, 2, 3, 4]
// (Clojure, PHP "range" )
const range = (start, stop, step) =>
Array.from({ length: (stop - start) / step + 1 }, (_, i) => start + i * step);
// 0..4
range(0, 4, 1);
// [0, 1, 2, 3, 4]
// 1...10
range(1, 10, 2);
// [1, 3, 5, 7, 9]
// `Array.from`
range("A".charCodeAt(0), "Z".charCodeAt(0), 1).map((x) =>
String.fromCharCode(x),
);
// ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
from() length .
function NotArray(len) {
console.log("NotArray called with length", len);
}
//
console.log(Array.from.call(NotArray, new Set(["foo", "bar", "baz"])));
// NotArray length undefined .
// NotArray { '0': 'foo', '1': 'bar', '2': 'baz', length: 3 }
//
console.log(Array.from.call(NotArray, { length: 1, 0: "foo" }));
// NotArray length 1 .
// NotArray { '0': 'foo', length: 1 }
this , Array .
console.log(Array.from.call({}, { length: 1, 0: "foo" })); // [ 'foo' ]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.from |
core-js Array.from ArrayArray()Array.of()Array.fromAsync()Array.prototype.map()TypedArray.from()This page was last modified on 2025 10 10 by MDN contributors.
Arrayat()concat()copyWithin()entries()every()fill()filter()find()findIndex()findLast()findLastIndex()flat()flatMap()forEach()includes()indexOf()join()keys()lastIndexOf()map()pop()push()reduce()reduceRight()reverse()shift()slice()some()sort()splice()toLocaleString()toReversed()toSorted()toSpliced()toString()unshift()values()with()[Symbol.iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |