Lodash - propertyOf method


Advertisements

Syntax

_.propertyOf(object)

The opposite of _.property; this method creates a function that returns the value at a given path of object.

Arguments

  • object (Object) − The object to query.

Output

  • (Function) − Returns the new accessor function.

Example

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)));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 2, 0 ]
[ 2, 0 ]
lodash_util.htm
Advertisements