Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年9月.
Array.of() 方法會由引數(arguments)的數量來建立一個新的 Array 實體,而不管引數的數量或類型為何。
Array.of() 與 Array 建構式之間的不同在於如何處理整數引數:Array.of(7) 會建立一個擁有單個元素—7—的陣列,而 Array(7) 會建立一個 length 屬性值為 7 的空陣列(**註:**這意味著這個陣列有 7 個空缺欄位(empty slots),而非 7 個值為 undefined 的欄位)。
要用來成為新建立之陣列的元素。
一個新的 Array 實體。
此函式是 ECMAScript 2015 標準的一部分。更多資訊可參考 Array.of and Array.from proposal 以及 Array.of polyfill。
可以在接受表示新陣列長度的單個參數的任何建構式上調用 of() 方法。
When the this value is not a constructor, a plain Array object is returned.
若所有執行環境沒有原生支援,可以在其他程式之前先執行以下程式碼來建立 Array.of()。
| ECMAScript® 2027 Language Specification # sec-array.of |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年7月14日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.