Skip to content

Array methods

  • .map(fn) makes a new array by transforming each item.
  • .filter(fn) makes a new array of only the items where fn returns true.
  • .forEach(fn) runs fn for each item, making no new array.

map(n => n * 2) turns 1, 2, 3 into 2, 4, 6; filter(n => n > 4) keeps 7 and 9 from 3, 7, 2, 9

Handout

Log in or create account

IGCSE, A-Level & AP