UNPKG

voca

Version:

The ultimate JavaScript string library

32 lines (27 loc) 884 B
'use strict'; require('./internal/is_nil.js'); require('./is_string.js'); var coerce_to_string = require('./internal/coerce_to_string.js'); /** * Returns the last occurrence index of `search` in `subject`. * * @function lastIndexOf * @static * @since 1.0.0 * @memberOf Index * @param {string} [subject=''] The string where to search. * @param {string} search The string to search. * @param {number} [fromIndex=subject.length - 1] The index to start searching backward in the string. * @return {number} Returns the last occurrence index or `-1` if not found. * @example * v.lastIndexOf('morning', 'n'); * // => 5 * * v.lastIndexOf('evening', 'o'); * // => -1 */ function lastIndexOf(subject, search, fromIndex) { var subjectString = coerce_to_string.coerceToString(subject); return subjectString.lastIndexOf(search, fromIndex); } module.exports = lastIndexOf;