Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var createFindIndex = require('../internal/createFindIndex');
2
3
/**
4
* This method is like `_.findIndex` except that it iterates over elements
5
* of `collection` from right to left.
6
*
7
* If a property name is provided for `predicate` the created `_.property`
8
* style callback returns the property value of the given element.
9
*
10
* If a value is also provided for `thisArg` the created `_.matchesProperty`
11
* style callback returns `true` for elements that have a matching property
12
* value, else `false`.
13
*
14
* If an object is provided for `predicate` the created `_.matches` style
15
* callback returns `true` for elements that have the properties of the given
16
* object, else `false`.
17
*
18
* @static
19
* @memberOf _
20
* @category Array
21
* @param {Array} array The array to search.
22
* @param {Function|Object|string} [predicate=_.identity] The function invoked
23
* per iteration.
24
* @param {*} [thisArg] The `this` binding of `predicate`.
25
* @returns {number} Returns the index of the found element, else `-1`.
26
* @example
27
*
28
* var users = [
29
* { 'user': 'barney', 'active': true },
30
* { 'user': 'fred', 'active': false },
31
* { 'user': 'pebbles', 'active': false }
32
* ];
33
*
34
* _.findLastIndex(users, function(chr) {
35
* return chr.user == 'pebbles';
36
* });
37
* // => 2
38
*
39
* // using the `_.matches` callback shorthand
40
* _.findLastIndex(users, { 'user': 'barney', 'active': true });
41
* // => 0
42
*
43
* // using the `_.matchesProperty` callback shorthand
44
* _.findLastIndex(users, 'active', false);
45
* // => 2
46
*
47
* // using the `_.property` callback shorthand
48
* _.findLastIndex(users, 'active');
49
* // => 0
50
*/
51
var findLastIndex = createFindIndex(true);
52
53
module.exports = findLastIndex;
54
55