當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Underscore.js _.allKeys()用法及代碼示例

_.allKeys()函數用於返回對象的所有鍵和繼承的屬性。

用法:

_.allKeys( object )

參數:該函數接受上述和以下描述的單個參數:

  • object:它包含對象元素,該對象元素包含鍵和值對的元素。

返回值:它返回對象的所有鍵和繼承的屬性。

以下示例說明了Underscore.js中的_.allKeys()函數:



範例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <script type="text/javascript" src= 
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> 
    </script> 
</head> 
  
<body> 
    <script type="text/javascript"> 
  
        var obj = { 
            Company:"GeeksforGeeks", 
            Address:"Noida", 
            Contact:"+91 9876543210", 
            Email:"abc@gfg.com" 
        } 
        console.log(_.allKeys(obj)); 
    </script> 
</body> 
  
</html>

輸出:

範例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <script type="text/javascript" src= 
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> 
    </script> 
</head> 
  
<body> 
    <script type="text/javascript"> 
  
        function Geeks(name) { 
            return this.name = name; 
        } 
  
        Geeks.prototype.GeeksforGeeks = true; 
  
        console.log(_.allKeys(new Geeks("Company"))); 
    </script> 
</body> 
  
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自AshokJaiswal大神的英文原創作品 Underscore.js | _.allKeys() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。