Lodash - keys 方法



語法

_.keys(object)

建立物件的自身可列舉屬性名稱陣列。

引數

  • object (Object)——要查詢的物件。

輸出

  • (Array)——返回屬性名稱陣列。

示例

var _ = require('lodash');
 
function Foo() {
   this.a = 1;
   this.b = 2;
}
Foo.prototype.c = 3;
var result = _.keys(new Foo);
console.log(result);

將上述程式儲存在 tester.js 中。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

[ 'a', 'b' ]
lodash_object.htm
廣告
© . All rights reserved.