Lodash property method
语法
Creates a function that returns the value at path of a given object.
参数
path (Array|string) − The path of the property to get.
输出
(Function) − Returns the new accessor function.
实例
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
输出