কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে অ্যাসোসিয়েটিভ অ্যারে কী?


অ্যাসোসিয়েটিভ অ্যারে জাভাস্ক্রিপ্টে মূলত অবজেক্ট যেখানে ইনডেক্সের बदলে ইউজার-ডিফাইনড কী ব্যবহার করা হয়। এগুলোর সাধারণ অ্যারে মতো length প্রপার্টি নেই এবং নরমাল for লুপ দিয়ে ট্রাভার্স করা যায় না।

উদাহরণ

<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style>    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } </style> </head> <body> <h1>Associative array in JavaScript</h1> <div style="color: green;" class="result"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to create a associative array and display it </h3> <script>    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {       let arr = { Name: "Rohan", Class: 9, Age: 16 };       for (i in arr) {          resEle.innerHTML += "Key = " + i + " : Value = " + arr[i] + "<br>";       }    }); </script> </body> </html>

আউটপুট

উপরোক্ত কোড নিম্নলিখিত আউটপুট তৈরি করবে −

জাভাস্ক্রিপ্টে অ্যাসোসিয়েটিভ অ্যারে কী?

'CLICK HERE' বাটনে ক্লিক করলে −

জাভাস্ক্রিপ্টে অ্যাসোসিয়েটিভ অ্যারে কী?

  1. জাভাস্ক্রিপ্ট সিম্বল কী?

  2. জাভাস্ক্রিপ্টে প্রমিস (Promises) কী?

  3. জাভাস্ক্রিপ্টে ফাংশন এক্সপ্রেশন কী?

  4. জাভাস্ক্রিপ্টে ক্লোジャー (Closures) কী?