Prototype - $H() Method



The $H() function converts objects into enumerable Hash objects that resemble associative arrays.

The $H function is the shorter way to obtain a hash.

Syntax

$H([obj])

Return Value

A hash object.

Example

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function ShowHash() {
            // let's create the object
            var a = {first: 10, second: 20, third: 30};
   
            // now transform it into a hash
            var h = $H(a);
            alert( h.toQueryString());
         }
      </script>
   </head>

   <body>
      <p>Click "Show Value" button to see the result</p>
      
      <form>
         <input type = "button" value = "Show Value" onclick = "ShowHash();"/>
      </form>
      
   </body>
</html>

Output

prototype_utility_methods.htm
Advertisements