property source npm

_.property(path)

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

Arguments

  1. path (Array|string)

    The path of the property to get.

Returns (Function)

Returns the new function.

Example

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

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

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