_.filter

Creates a new array with all elements that pass the test implemented by the provided function.

  1. // Underscore/Lodash
  2. function isBigEnough (value) {
  3. return value >= 10
  4. }
  5. var array = [12, 5, 8, 130, 44]
  6. var filtered = _.filter(array, isBigEnough)
  7. console.log(filtered)
  8. // output: [12, 130, 44]
  9.  
  10. // Native
  11. function isBigEnough (value) {
  12. return value >= 10
  13. }
  14. var array = [12, 5, 8, 130, 44]
  15. var filtered = array.filter(isBigEnough)
  16. console.log(filtered)
  17. // output: [12, 130, 44]

Browser Support for Array.prototype.filter()

ChromeEdgeFirefoxIEOperaSafari
1.5 ✔9 ✔