_.lastIndexOf

Returns the index of the last occurrence of value in the array, or -1 if value is not present.

  1. // Underscore/Lodash
  2. var array = [2, 9, 9, 4, 3, 6]
  3. var result = _.lastIndexOf(array, 9)
  4. console.log(result)
  5. // output: 2
  6.  
  7. // Native
  8. var array = [2, 9, 9, 4, 3, 6]
  9. var result = array.lastIndexOf(9)
  10. console.log(result)
  11. // output: 2

Browser Support for Array.prototype.lastIndexOf()

ChromeEdgeFirefoxIEOperaSafari
1.5 ✔9.0 ✔