1 var indexOfNaN = require('./_indexOfNaN'),
2 toInteger = require('./toInteger');
4 /* Built-in method references for those with the same name as other `lodash` methods. */
5 var nativeMax = Math.max,
9 * This method is like `_.indexOf` except that it iterates over elements of
10 * `array` from right to left.
15 * @param {Array} array The array to search.
16 * @param {*} value The value to search for.
17 * @param {number} [fromIndex=array.length-1] The index to search from.
18 * @returns {number} Returns the index of the matched value, else `-1`.
21 * _.lastIndexOf([1, 2, 1, 2], 2);
24 * // Search from the `fromIndex`.
25 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
28 function lastIndexOf(array, value, fromIndex) {
29 var length = array ? array.length : 0;
34 if (fromIndex !== undefined) {
35 index = toInteger(fromIndex);
36 index = (index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1)) + 1;
38 if (value !== value) {
39 return indexOfNaN(array, index, true);
42 if (array[index] === value) {
49 module.exports = lastIndexOf;