জাভাস্ক্রিপ্টের Array.of() মেথড প্যারামিটার ভ্যালু হিসেবে ভেরিয়েবল দিয়ে একটি নতুন অ্যারে ইনস্ট্যান্স তৈরি করতে ব্যবহৃত হয়।
সিনট্যাক্স:
Array.of(elements....)
এখানে elements হলো প্যারামিটার ভ্যালু হিসেবে মানগুলো।
উদাহরণ
<!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>
আউটপুট
কনসোলে [10, 20, 30, 40, 50] দেখাবে।
উদাহরণ ২
<!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>