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

Array.of() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Array.of()

20159

Array.of() Array

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(element0)
Array.of(element0, element1)
Array.of(element0, element1, /*  ,*/ elementN)

elementN

Array

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

js
Array.of(7); // [7]
Array(7); //  7 

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 called with length 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 ]

ECMAScript 2027 LanguageSpecification
# sec-array.of


Web Proxy Viewer  |  New URL  |  Original Page