| Create |
Array() |
new Array(3) |
Array |
Create array with length |
Array.of() |
Array.of(1, 2, 3) |
Array |
Create array from values |
Array.from() |
Array.from('abc') |
Array |
Create array from iterable |
[...] |
[1, 2, 3] |
Array |
Array literal |
| Add / Modify |
.push(item) |
arr.push(4) |
number |
Add to end, return new length |
.unshift(item) |
arr.unshift(0) |
number |
Add to start, return new length |
.splice(i, del, ...items) |
arr.splice(1, 0, 'x') |
Array |
Add/remove at index |
.fill(value, start, end) |
arr.fill(0, 2, 4) |
Array |
Fill with value |
| Remove |
.pop() |
arr.pop() |
item |
Remove last, return it |
.shift() |
arr.shift() |
item |
Remove first, return it |
.splice(i, count) |
arr.splice(1, 2) |
Array |
Remove count items at index |
| Access |
arr[i] |
arr[0] |
item |
Get element at index |
.at(i) |
arr.at(-1) |
item |
Get element (supports negative) |
.slice(start, end) |
arr.slice(1, 3) |
Array |
Get subarray |
| Search |
.indexOf(item) |
arr.indexOf(5) |
number |
First index or -1 |
.lastIndexOf(item) |
arr.lastIndexOf(5) |
number |
Last index or -1 |
.includes(item) |
arr.includes(5) |
boolean |
Check if exists |
.find(fn) |
arr.find(x => x > 10) |
item |
First match or undefined |
.findIndex(fn) |
arr.findIndex(x => x > 10) |
number |
First match index or -1 |
.findLast(fn) |
arr.findLast(x => x > 10) |
item |
Last match or undefined |
.findLastIndex(fn) |
arr.findLastIndex(x => x > 10) |
number |
Last match index or -1 |
| Test |
.every(fn) |
arr.every(x => x > 0) |
boolean |
All elements match |
.some(fn) |
arr.some(x => x > 10) |
boolean |
At least one matches |
| Transform |
.map(fn) |
arr.map(x => x * 2) |
Array |
Transform each element |
.filter(fn) |
arr.filter(x => x > 5) |
Array |
Keep matching elements |
.reduce(fn, init) |
arr.reduce((a, b) => a + b, 0) |
any |
Reduce to single value |
.reduceRight(fn, init) |
arr.reduceRight((a, b) => a + b) |
any |
Reduce from right |
.flatMap(fn) |
arr.flatMap(x => [x, x*2]) |
Array |
Map then flatten |
.flat(depth) |
arr.flat(2) |
Array |
Flatten nested arrays |
| Sort / Reverse |
.sort(fn) |
arr.sort((a, b) => a - b) |
Array |
Sort in place |
.reverse() |
arr.reverse() |
Array |
Reverse in place |
.toSorted(fn) |
arr.toSorted((a, b) => a - b) |
Array |
Sort (copy) |
.toReversed() |
arr.toReversed() |
Array |
Reverse (copy) |
| Iterate |
.forEach(fn) |
arr.forEach(x => console.log(x)) |
undefined |
Run function for each |
.keys() |
arr.keys() |
Iterator |
Iterator of indices |
.values() |
arr.values() |
Iterator |
Iterator of values |
.entries() |
arr.entries() |
Iterator |
Iterator of [index, value] |
| Join / Combine |
.concat(...arrays) |
arr.concat([4, 5]) |
Array |
Merge arrays |
.join(separator) |
arr.join(', ') |
string |
Join to string |
[...arr1, ...arr2] |
[...a, ...b] |
Array |
Spread operator merge |
| Copy / Modify |
.slice() |
arr.slice() |
Array |
Shallow copy |
.with(i, value) |
arr.with(0, 99) |
Array |
Copy with replaced value |
.toSpliced(i, del, ...items) |
arr.toSpliced(1, 1, 'x') |
Array |
Splice (copy) |
| Info |
.length |
arr.length |
number |
Number of elements |
.isArray(obj) |
Array.isArray([]) |
boolean |
Check if array |
| String-like |
.toString() |
arr.toString() |
string |
Convert to string |
.toLocaleString() |
arr.toLocaleString() |
string |
Locale string |
| Advanced |
.copyWithin(target, start, end) |
arr.copyWithin(0, 3, 5) |
Array |
Copy part within array |
.from(iter, mapFn) |
Array.from([1,2], x => x*2) |
Array |
Create and map |