_.property

_.property(path)

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

1
2
3
4
5
6
7
8
9
10
11
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]
doc_Lodash
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.