_.indexOf

Returns the first index at which a given element can be found in the array, or -1 if it is not present.

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

Browser Support for Array.prototype.indexOf()

ChromeEdgeFirefoxIEOperaSafari
1.5 ✔9.0 ✔