Lodash - propertyOf 方法



語法

_.propertyOf(object)

與 _.property 相反;該方法會建立一個在物件給定路徑下返回相應值的函式。

引數

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

輸出

  • (Function) − 返回新訪問器函式。

示例

var _ = require('lodash');
var array = [0, 1, 2];
var object = { 'a': array, 'b': array, 'c': array };
 
console.log(_.map(['a[2]', 'c[0]'], _.propertyOf(object)));
console.log(_.map([['a', '2'], ['c', '0']], _.propertyOf(object)));

將上述程式儲存到 tester.js 中。執行以下命令以執行該程式。

命令

\>node tester.js

輸出

[ 2, 0 ]
[ 2, 0 ]
lodash_util.htm
廣告
© . All rights reserved.