How to use associative array/hashing in JavaScript?

JavascriptWeb DevelopmentFront End Technology

JavaScript does not support Associative array. Arrays in JavaScript work with numbered indexes. Here is an example −

Example

<!DOCTYPE html>
<html>
   <body>
      <p id="test"></p>
      <script>
         var dept = [];
         dept[0] = "Amit";
         dept[1] = "Technical";
         dept[2] = 045;

         document.getElementById("test").innerHTML = dept[1] + " " + dept.length;
      </script>
   </body>
</html>
raja
Published on 29-Jan-2018 14:45:03
Advertisements