जावास्क्रिप्ट की Array.of () विधि का उपयोग पैरामीटर मानों के रूप में चर के साथ एक नया सरणी उदाहरण बनाने के लिए किया जाता है।
वाक्य रचना इस प्रकार है -
Array.of(elements....)
ऊपर, तत्व पैरामीटर मान के रूप में मान हैं।
आइए अब जावास्क्रिप्ट में 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> आउटपुट

"परिणाम" बटन पर क्लिक करें और कंसोल में परिणाम देखें -
