主题
property
js
_.property(path)
创建一个函数,返回给定对象的 path
值。
¥Creates a function that returns the value at path
of a given object.
新增于
¥Since
2.4.0
参数
¥Arguments
path
(数组|字符串):要获取的属性的路径。¥
path
(Array|string): The path of the property to get.
返回
¥Returns
(函数):返回新的访问器函数。
¥(Function): Returns the new accessor function.
示例
¥Example
js
var objects = [
{ 'a': { 'b': 2 } },
{ 'a': { 'b': 1 } }
];
_.map(objects, _.property('a.b'));
// => [2, 1]
_.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
// => [1, 2]