原型 - unset() 方法



此方法刪除雜湊鍵的屬性並返回其值。如果在雜湊中沒有找到該鍵,則無所操作並返回 undefined。

語法

hash.unset(key);

返回值

返回已刪除鍵的值。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var h = new Hash({ a: 'apple', b: 'banana', c: 'coconut' });
            // Returns 'apple'
            alert( "h.unset('a') : " +  h.unset('a') );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

輸出

prototype_hash_processing.htm
廣告