Complete reference for JavaScript array methods: map, filter, reduce, forEach, find, sort, slice, splice, and more. With code examples.
| Method | Description |
Array.from(iterable) | Create array from iterable. Array.from("abc") → ["a", "b", "c"] |
Array.from(obj, mapFn) | Create and map in one step. Array.from({length: 3}, (_, i) => i) → [0, 1, 2] |
Array.of(...items) | Create array from arguments. Array.of(1, 2, 3) → [1, 2, 3] |
[...iterable] | Spread into new array. [..."abc"] → ["a", "b", "c"] |
Array.isArray(value) | Check if value is an array. Array.isArray([1, 2]) → true |
Array(n).fill(val) | Create filled array. Array(3).fill(0) → [0, 0, 0] |
[...new Set(arr)] | Remove duplicates. [...new Set([1,1,2,3])] → [1, 2, 3] |
structuredClone(arr) | Deep clone an array (including nested objects and arrays) |
| Method | Description |
arr.push(item) | Add element(s) to the end. Returns new length. [1,2].push(3) → array is [1,2,3] |
arr.pop() | Remove and return the last element. [1,2,3].pop() → 3 |
arr.unshift(item) | Add element(s) to the beginning. Returns new length. [2,3].unshift(1) → array is [1,2,3] |
arr.shift() | Remove and return the first element. [1,2,3].shift() → 1 |
arr.splice(start, count) | Remove count elements at start. [1,2,3,4].splice(1, 2) → removes [2,3] |
arr.splice(start, 0, ...items) | Insert items at start without removing. [1,4].splice(1, 0, 2, 3) → [1,2,3,4] |
arr.splice(start, count, ...items) | Replace count elements with new items. [1,2,3].splice(1, 1, "a") → [1,"a",3] |
arr.fill(val, start, end) | Fill with value from start to end. [1,2,3,4].fill(0, 1, 3) → [1,0,0,4] |
arr.copyWithin(target, start) | Copy part of array to another position. [1,2,3,4].copyWithin(0, 2) → [3,4,3,4] |
delete arr[i] | Delete element (leaves undefined hole). Prefer splice() instead |
arr.length = n | Truncate array to n elements. arr = [1,2,3]; arr.length = 1 → [1] |
| Method | Description |
arr.find(fn) | Return first element where fn returns true. [1,2,3].find(x => x > 1) → 2 |
arr.findIndex(fn) | Return index of first match or -1. [1,2,3].findIndex(x => x > 1) → 1 |
arr.findLast(fn) | Return last element where fn returns true (ES2023). [1,2,3].findLast(x => x > 1) → 3 |
arr.findLastIndex(fn) | Return index of last match or -1 (ES2023) |
arr.indexOf(val) | Return first index of val or -1. [1,2,3,2].indexOf(2) → 1 |
arr.lastIndexOf(val) | Return last index of val or -1. [1,2,3,2].lastIndexOf(2) → 3 |
arr.includes(val) | Check if array contains val. [1,2,3].includes(2) → true |
arr.some(fn) | True if at least one element passes fn. [1,2,3].some(x => x > 2) → true |
arr.every(fn) | True if all elements pass fn. [1,2,3].every(x => x > 0) → true |
| Method | Description |
arr.map(fn) | Return new array with fn applied to each element. [1,2,3].map(x => x * 2) → [2,4,6] |
arr.filter(fn) | Return new array with elements where fn is true. [1,2,3].filter(x => x > 1) → [2,3] |
arr.reduce(fn, init) | Reduce to single value. [1,2,3].reduce((sum, x) => sum + x, 0) → 6 |
arr.reduceRight(fn, init) | Reduce from right to left. ["a","b","c"].reduceRight((s, x) => s + x, "") → "cba" |
arr.flat(depth) | Flatten nested arrays. [1,[2,[3]]].flat(2) → [1,2,3] |
arr.flat(Infinity) | Flatten all levels. [1,[2,[3,[4]]]].flat(Infinity) → [1,2,3,4] |
arr.flatMap(fn) | Map then flatten one level. [1,2].flatMap(x => [x, x*2]) → [1,2,2,4] |
arr.sort() | Sort in place (lexicographic). ["b","a","c"].sort() → ["a","b","c"] |
arr.sort((a, b) => a - b) | Sort numbers ascending. [3,1,2].sort((a,b) => a - b) → [1,2,3] |
arr.sort((a, b) => b - a) | Sort numbers descending. [1,3,2].sort((a,b) => b - a) → [3,2,1] |
arr.toSorted(fn) | Return sorted copy without mutating original (ES2023) |
arr.reverse() | Reverse array in place. [1,2,3].reverse() → [3,2,1] |
arr.toReversed() | Return reversed copy without mutating original (ES2023) |
arr.with(index, value) | Return copy with element at index replaced (ES2023). [1,2,3].with(1, 9) → [1,9,3] |
arr.toSpliced(start, count, ...items) | Non-mutating version of splice() (ES2023) |
| Method | Description |
arr.slice(start, end) | Return shallow copy from start to end. [1,2,3,4].slice(1, 3) → [2,3] |
arr.slice(start) | From start to end. [1,2,3].slice(1) → [2,3] |
arr.slice(-n) | Last n elements. [1,2,3,4].slice(-2) → [3,4] |
arr.slice() | Shallow copy entire array. [1,2,3].slice() → [1,2,3] |
arr.concat(arr2) | Merge arrays. [1,2].concat([3,4]) → [1,2,3,4] |
[...arr1, ...arr2] | Merge with spread. [...[1,2], ...[3,4]] → [1,2,3,4] |
arr.join(sep) | Join elements into string. [1,2,3].join("-") → "1-2-3" |
arr.join() | Join with commas (default). [1,2,3].join() → "1,2,3" |
arr.toString() | Convert to comma-separated string. [1,2,3].toString() → "1,2,3" |
arr.at(index) | Access element by index (supports negative). [1,2,3].at(-1) → 3 |
| Method | Description |
arr.forEach(fn) | Execute fn for each element. [1,2,3].forEach(x => console.log(x)) |
arr.forEach((val, idx, arr) => {}) | Callback receives value, index, and the original array |
for (const val of arr) | Iterate over values. Supports break and continue (unlike forEach) |
for (const [i, val] of arr.entries()) | Iterate with index and value using destructuring |
arr.entries() | Return iterator of [index, value] pairs |
arr.keys() | Return iterator of indices. [...["a","b"].keys()] → [0, 1] |
arr.values() | Return iterator of values. [...["a","b"].values()] → ["a", "b"] |
for (const key in arr) | Iterate over indices as strings (avoid — also iterates inherited properties) |