JavaScript Array.of() 函式
JavaScript 的 Array.of() 方法用於建立新的陣列例項,變數作為引數值。
語法如下 −
Array.of(elements....)
以上,elements 是作為引數值的值。
現在讓我們實現 JavaScript 中的 Array.of() 方法 −
示例
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Click the button to display the values in Console</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
function display() {
console.log(Array.of(10, 20, 30, 40 ,50));
}
</script>
</body>
</html>輸出

單擊“結果”,在輸出控制檯中檢視 −

示例
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Get the student names with top 5 ranks...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
function display() {
console.log(Array.of("Kevin", "Tom", "Ryan", "Jacob", "Jack"));
}
</script>
</body>
</html>輸出

單擊“結果”按鈕,在輸出控制檯中檢視結果 −

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP