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>

輸出

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

更新日期: 2019-12-17

74 次瀏覽

啟動您的 職業生涯

完成課程獲取認證

開始學習
廣告
© . All rights reserved.