Skip to content

Instantly share code, notes, and snippets.

@pelatge
Forked from joyrexus/README.md
Created May 20, 2020 00:14
Show Gist options
  • Save pelatge/3d63778612f941c9413cd0c5420cf5ce to your computer and use it in GitHub Desktop.
Save pelatge/3d63778612f941c9413cd0c5420cf5ce to your computer and use it in GitHub Desktop.
JavaScript array methods

JavaScript Array Methods

Excerpted from the D3 API docs.

Note esp. usage of the map, filter, and reduce iteration methods. For a nice intro to these methods, see Tom MacWright's talk Beyond the For Loop, and for quick guidance on when to use which iteration method, see this gist.

Mutation Methods

That modify the array:

Accessor Methods

That return some representation of the array:

Iteration Methods

That apply functions to elements in the array:

  • array.filter - Create a new array with only the elements for which a predicate is true.
  • array.forEach - Call a function for each element in the array.
  • array.every - See if every element in the array satisfies a predicate.
  • array.map - Create a new array with the result of a function of every element in the array.
  • array.some - See if at least one element in the array satisfies a predicate.
  • array.reduce - Apply a function to reduce the array to a single value (from left-to-right).
  • array.reduceRight - Apply a function to reduce the array to a single value (from right-to-left).

Power Tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment