# Array methods for data manipulation

*JavaScript Developer Study Guide · Variables, Types, and Collections · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/javascript-developer/variables-types-and-collections/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.

- Certification: Salesforce JavaScript Developer
- Exam section: Variables, Types, and Collections
- Study guide: https://www.certifyforce.com/study-guide/javascript-developer

**Official exam objective:**

> Given a list of data, demonstrate data manipulation with arrays.

## 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

| Fact | Detail | Source |
|---|---|---|
| Default `sort()` | String comparison by UTF-16 code units, in place | [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) |
| `toSorted()` | Copying version of `sort()`; original unchanged | [Array.prototype.toSorted()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted) |
| `sort()` return | The same array reference | [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) |
| `push()` return | New length | [Array.prototype.push()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) |
| `splice()` return | Removed elements; mutates | [Array.prototype.splice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) |
| `slice(start, end)` | `end` excluded; original unchanged | [Array.prototype.slice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) |
| `forEach()` return | `undefined` | [Array.prototype.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) |
| `reduce()` without initial value | Accumulator starts as `array[0]`; empty array throws `TypeError` | [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) |
| `[].every(fn)` | `true` | [Array.prototype.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) |
| `indexOf(NaN)` / `includes(NaN)` | -1 / `true` | [Array.prototype.includes()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) |
| `flat()` depth | Defaults to 1 | [Array.prototype.flat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) |
| Spread, `slice`, `concat`, `Array.from` | Shallow copies | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) |
| `fill(obj)` | Every slot references the same object | [Array.prototype.fill()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) |
| `Map` keys | Any value; objects matched by identity | [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) |

## Check yourself

- 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?

## Sources

- [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
- [Indexed collections](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections)
- [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
- [Array.prototype.splice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
- [Array.prototype.slice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
- [Array.prototype.push()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
- [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)
- [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
- [Array.prototype.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
- [Array.prototype.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
- [Array.prototype.includes()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
- [Array.prototype.indexOf()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
- [Array.prototype.fill()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
- [Array.from()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
- [Array.prototype.flat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
- [Array.prototype.join()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
- [Spread syntax (...)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)
- [Destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring)
- [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
- [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
- [Array.prototype.toSorted()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
- [Array.prototype.toReversed()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 14 linked practice questions, and unlimited timed mock exams are included with the JavaScript Developer pack (USD $19): https://www.certifyforce.com/practice-exams
