[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/of [Back]  [Original]

Array.of() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.of()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 9.

array.of() Array .

In this article

console.log(Array.of("foo", 2, "bar", true));
// Expected output: Array ["foo", 2, "bar", true]

console.log(Array.of());
// Expected output: Array []

js
Array.of()
Array.of(element1)
Array.of(element1, element2)
Array.of(element1, element2, /* , */ elementN)

element1, , elementN

.

Array .

Array.of() Array() . Array.of(7) 7 , Array(7) length 7 . ( undefined 7 .)

js
Array.of(7); // [7]
Array(7); // array of 7 empty slots

Array.of(1, 2, 3); // [1, 2, 3]
Array(1, 2, 3); // [1, 2, 3]

Array.of() . , Array of() , of() Array . this , of() . length . this Array .

Array.of()

js
Array.of(1); // [1]
Array.of(1, 2, 3); // [1, 2, 3]
Array.of(undefined); // [undefined]

of()

of() .

js
function NotArray(len) {
  console.log("NotArray called with length", len);
}

console.log(Array.of.call(NotArray, 1, 2, 3));
// NotArray  3 .
// NotArray { '0': 1, '1': 2, '2': 3, length: 3 }

console.log(Array.of.call(Object)); // [Number: 0] { length: 0 }

this , Array .

js
console.log(Array.of.call({}, 1)); // [ 1 ]

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.of


Web Proxy Viewer  |  New URL  |  Original Page