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