Which method changes the array it is called on?
sort works in place and returns the same array. map, filter and flatMap return new arrays. Use toSorted for a sorted copy.
Array Methods · Exercise 1 of 4
Fifteen multiple-choice questions on JavaScript array methods: map, filter, reduce, forEach, find and findIndex, findLast, some and every, flat and flatMap, callback arguments, sorting stability and which methods mutate. Pick an option to check your answer instantly.
Which method changes the array it is called on?
sort works in place and returns the same array. map, filter and flatMap return new arrays. Use toSorted for a sorted copy.
In what order does map pass arguments to its callback?
All the iteration methods (forEach, map, filter, find, some, every …) use (element, index, array). reduce adds the accumulator first.
In arr.reduce((acc, x) => acc + x, 0), what is acc on each call?
The accumulator carries the running result from one call to the next; the final one is reduce's return value.
For const logs = [{ ok: true }, { ok: false, id: 1 }, { ok: false, id: 2 }];, what is logs.findLast((l) => !l.ok).id?
findLast (ES2023) searches from the end, so it returns the latest failure. find would return id 1.
Students are sorted by marks only. What happens to two students with equal marks?
Stability means a comparator returning 0 keeps the original order, which lets you sort by several keys in sequence or rely on existing order for ties.
Timed online tests with instant scores and explanations.