- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - property method
Syntax
_.property(path)
Creates a function that returns the value at path of a given object.
Arguments
path (Array|string) − The path of the property to get.
Output
(Function) − Returns the new accessor function.
Example
var _ = require('lodash'); var objects = [ { 'a': { 'b': 2 } }, { 'a': { 'b': 1 } } ]; var result = _.map(objects, _.property('a.b')); console.log(result); result = _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b'); console.log(result);
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
[ 2, 1 ] [ 1, 2 ]
lodash_util.htm
Advertisements