r/learnjavascript • • May 02 '19

Top 10 JavaScript Array Methods

https://www.youtube.com/watch?v=NH_lCxa1hv8
7 Upvotes

4 comments sorted by

7

u/inabahare May 02 '19
  1. forEach

  2. includes

  3. filter

  4. map

  5. reduce

  6. some

  7. every

  8. sort

  9. reverse

  10. concat

1

u/HolidayInternet May 02 '19

Thanks for the tldr!

4

u/GSLint May 02 '19

sort((a, b) => a < b) isn't really correct and only works/worked in some environments. For example, it no longer works in Chrome 70 and Node 11.

sort expects a number as the return value, not a boolean. The number should be negative if a should come before b, positive if b should come before a and 0 if they're equal. If you're sorting numbers, sort((a, b) => a - b) gives you an ascending order and sort((a, b) => b - a) gives you a descending one.