_.includes

Checks if a value is in collection.

  1. var array = [1, 2, 3]
  2. // Underscore/Lodash - also called _.contains
  3. _.includes(array, 1)
  4. // output: true
  5.  
  6. // Native
  7. var array = [1, 2, 3]
  8. array.includes(1)
  9. // output: true
  10.  
  11. // Native (does not use same value zero)
  12. var array = [1, 2, 3]
  13. array.indexOf(1) > -1
  14. // output: true

Browser Support for Array.prototype.includes

ChromeEdgeFirefoxIEOperaSafari
47.0 ✔14.0 ✔43.0 ✔34.0 ✔9.0 ✔

Browser Support for Array.prototype.indexOf

ChromeEdgeFirefoxIEOperaSafari
1.5 ✔9.0 ✔