Javascript arrays come with a large amount of built-in methods. It’s impossible (and unnecessary) to memorize all of them. A better approach is to learn about them gradually: understand what each method does, when it’s useful and try it out in real code.
Over time, as you experiment and build real projects, you’ll naturally start remembering the ones you use most and your code will be cleaner, safer and even easier to maintain.
This guide organizes almost every array method with clear examples into easy-to-read tables. Consider it your roadmap for learning arrays step by step.
If you’re just starting out, this quick intro is a great place to begin: 6 Must-Know JavaScript Array Methods (With Simple Examples)
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| map() | No | Transform each item; returns the same-length new array. | [1,2,3].map(n => n * 2) | [2,4,6] | Use for one-to-one transformations; avoid side-effects (forEach instead). |
| flatMap() | No | map() followed by one-level flattening. | [1,2].flatMap(n => [n, n * 2]) | [1,2,2,4] | Useful for mapping + expanding values. |
| flat() | No | Flattens nested arrays by a given depth. | [1,[2,[3]]].flat(2) | [1,2,3] | Deep flattening can be expensive. |
2. Filtering & Searching
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| filter() | No | Returns items matching a condition. | [1,2,3,4].filter(n => n % 2 === 0) | [2,4] | Creates a new, shorter array. |
| find() | No | Returns the first matching item. | [3,6,9].find(n => n > 4) | 6 | Stops as soon as it finds a match. |
| findIndex() | No | Returns index of the first match. | [3,6,9].findIndex(n => n > 4) | 1 | - |
| findLast() | No | Returns the last matching item. | [1,2,3,4].findLast(n => n < 4) | 3 | Searches from the end. |
| findLastIndex() | No | Index of the last match. | [1,2,3,4].findLastIndex(n => n < 4) | 2 | - |
| includes() | No | Checks if a value exists. | ['a','b'].includes('a') | true | More readable than indexOf(). |
3. Reducing & Aggregation
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| reduce() | No | Combine items left → right into one output. | [1,2,3].reduce((a,n) => a + n, 0) | 6 | Works for sums, grouping, flattening, etc. |
| reduceRight() | No | Like reduce() but right → left. | ['a','b','c'].reduceRight((a,c) => a + c) | 'cba' | Useful for right-associative operations. |
4. Condition Checking
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| some() | No | Returns true if any value matches. | [1,3,5].some(n => n % 2 === 0) | false | Stops early for efficiency. |
| every() | No | True only if all values match. | [2,4,6].every(n => n % 2 === 0) | true | Useful for validation checks. |
5. Sorting & Reordering
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| sort() | Yes | Sort array in place. | [3,1,2].sort() | [1,2,3] | Mutates — be careful with shared state. |
| reverse() | Yes | Reverse array in place. | [1,2,3].reverse() | [3,2,1] | Mutates. |
| toSorted() | No | Returns a sorted copy. | [3,1,2].toSorted() | [1,2,3] | Safe alternative to sort(). |
| toReversed() | No | Returns a reversed copy. | [1,2,3].toReversed() | [3,2,1] | Safe alternative to reverse(). |
6. Adding & Removing Items (Mutating)
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| push() | Yes | Add item(s) to the end. | arr.push(4) | 4 | Returns new length. |
| pop() | Yes | Remove item from the end. | arr.pop() | 4 | Returns removed item. |
| shift() | Yes | Remove first item. | arr.shift() | 1 | Slower than pop(). |
| unshift() | Yes | Add item(s) to the start. | arr.unshift(0) | 4 | Returns new length. |
| splice() | Yes | Add/remove at any index. | arr.splice(1,1) | [2] | Extremely flexible but mutates. |
7. Non-Mutating Alternatives
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| slice() | No | Extract a portion. | [1,2,3].slice(1) | [2,3] | Commonly used to copy arrays. |
| concat() | No | Merge arrays. | [1].concat([2,3]) | [1,2,3] | Can replace push() for immutable code. |
| toSpliced() | No | Non-mutating version of splice(). | [1,2,3].toSpliced(1,1) | [1,3] | Ideal for React/immutable patterns. |
8. Combining & Converting
| Function | Mutates? | What It Does | Example | Output | Notes |
|---|
| join() | No | Turn array into string. | ['a','b'].join('-') | 'a-b' | Good for CSV, lists, paths. |
| Array.from() | No | Convert iterable → array. | Array.from('hi') | ['h','i'] | Works with NodeLists, Sets, etc. |
| Array.of() | No | Create an array from arguments. | Array.of(1,2) | [1,2] | Avoids quirks of new Array(). |
| Array.isArray() | No | Check if value is an array. | Array.isArray([]) | true | - |
| indexOf() | No | First index of a value. | ['a','b','a'].indexOf('a') | 0 | Use includes() when checking existence. |
| lastIndexOf() | No | Last index of a value. | ['a','b','a'].lastIndexOf('a') | 2 | - |
| at() | No | Access by index (supports negatives). | [1,2,3].at(-1) | 3 | Cleaner than arr[arr.length - 1]. |
Final Summary
A compact overview with recommended use-cases.
| Category | Methods | Recommended Use |
|---|
| Transform | map, flat, flatMap, reduce, reduceRight | Converting data, mapping, flattening, building new results. |
| Filter/Search | filter, find, findIndex, findLast, findLastIndex, some, every, includes | Extracting items, locating values, validation checks. |
| Reorder | sort, reverse, toSorted, toReversed | Sorting or reversing data; prefer non-mutating versions. |
| Add/Remove | push, pop, shift, unshift, splice, slice, toSpliced, concat | Managing list changes; choose non-mutating alternatives. |
| Utility | flat, join, Array.from, Array.of, Array.isArray, indexOf, lastIndexOf, at | Formatting, conversions, type checking, index lookups. |
Final Thoughts
A few friendly tips to keep in mind as you explore javascript arrays:
- Don’t stress about memorization, focus on understanding what each method does and practicing it in small projects.
- Use mutating methods when you intentionally want to change the original array.
- Use non-mutating methods to write safer, predictable code.
Remember, it’s not about knowing every method; it’s about knowing the right one for the job and using them effectively. Take it step by step, and your array skills will grow naturally.
Happy learning and thank you for reading!