Skip to main content

property

_.property(path) # Ⓢ [Ⓣ][1] Ⓝ

Creates a function that returns the value at path of a given object.

Since​

2.4.0

Arguments​

  1. path (Array|string): The path of the property to get.

Returns​

(Function): Returns the new accessor function.

Example​

var objects = [
{ 'a': { 'b': 2 } },
{ 'a': { 'b': 1 } }
];

_.map(_.property('a.b'), objects);
// => [2, 1]

_.map('a.b', _.sortBy(objects, _.property(['a', 'b'])));
// => [1, 2]