All cheat sheets

JavaScript

JS arrays cheat sheet

Array and object helpers in modern JavaScript, including the non-mutating copies added in ES2023 and grouping helpers, with notes on which methods mutate.

Create

Access

Transform

Immutable

Objects

Things worth remembering

  • sort, reverse, splice, push and fill mutate. toSorted, toReversed, toSpliced and with return copies.
  • sort() compares strings by default, so [10, 9].sort() gives [10, 9]. Always pass a comparator for numbers.
  • Array.from({ length: n }, mapFn) is the cleanest way to build a range without a loop.

More JavaScript sheets