Lodash教程

Lodash property method

语法

_.property(path)
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

\>node tester.js

输出

[ 2, 1 ]
[ 1, 2 ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4