Variables, Types, and Collections23% of the exam

Array methods for data manipulation

Which array methods mutate and which return copies, what each one returns (map, filter, reduce, find, findIndex, some, every, includes, flat, forEach), the default string sort and comparators, shallow copies with spread, array destructuring, and Set and Map as collections.

Official exam objective
Given a list of data, demonstrate data manipulation with arrays.

~6 min read · 14 practice questions ·

What the exam expects

  • Tell mutating methods (push, pop, shift, unshift, splice, sort, reverse, fill) from copying ones (concat, slice, map, filter, flat, spread) and predict what each returns.
  • Pick the right query method for a requirement: find, findIndex, filter, some, every, includes, indexOf.
  • Sort numbers and objects with a comparator, and total values with reduce and an initial value.
  • Copy arrays safely (shallow copies, fill with objects, Array.from) and unpack them with destructuring.
  • Remove duplicates and key data by any value with Set and Map.
  • Key terms: mutating method (changes the array it is called on); shallow copy (a new array whose object elements are still the same references); callback (the function an iterative method calls with element, index and array); comparator (a sort function returning negative, zero or positive); sparse array (an array with empty slots).

Key facts

Default sort()
Detail
String comparison by UTF-16 code units, in place
toSorted()
Detail
Copying version of sort(); original unchanged
sort() return
Detail
The same array reference
push() return
Detail
New length
splice() return
Detail
Removed elements; mutates
slice(start, end)
Detail
end excluded; original unchanged
forEach() return
Detail
undefined
reduce() without initial value
Detail
Accumulator starts as array[0]; empty array throws TypeError
indexOf(NaN) / includes(NaN)
Detail
-1 / true
flat() depth
Detail
Defaults to 1
Spread, slice, concat, Array.from
Detail
Shallow copies
fill(obj)
Detail
Every slot references the same object
Map keys
Detail
Any value; objects matched by identity
Sources for this section (13)
  • Why does `new Array(3).fill([])` make all three slots change together?
  • When should you use `find()` instead of `filter()`?
  • Why does `readings.indexOf(NaN)` return -1 while `includes(NaN)` returns `true`?
  • What does `[].every((x) => x > 0)` return?
  • Which expression returns unique tags as an array in original order?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the JavaScript Developer pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 24 lessons of the JavaScript Developer guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Inline practice questions and one-click topic practice (14 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the JavaScript Developer exam