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.