Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active September 21, 2022 06:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save joyrexus/7366429 to your computer and use it in GitHub Desktop.
Save joyrexus/7366429 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