JavaScript Array Functions
Creating and Checking Arrays
Function Description
Array.isArray(arr) Checks if the value is an array.
Array.of(...items) Creates a new array with the given elements.
Array.from(obj) Creates a new array from an iterable or array-like object.
Adding and Removing Elements
Function Description
push(item) Adds one or more items to the end of the array.
pop() Removes the last item from the array.
unshift(item) Adds one or more items to the beginning of the array.
shift() Removes the first item from the array.
splice(start, deleteCount, ...items)
Adds/removes elements at a specific index.
slice(start, end) Returns a new array with a portion of the original.
Searching and Testing
Function Description
includes(value) Checks if the array includes a value.
indexOf(value) Returns the first index of the value (or -1).
lastIndexOf(value) Returns the last index of the value (or -1).
find(callback) Returns the first item that matches a condition.
findIndex(callback) Returns the index of the first item that matches.
some(callback) Returns true if any item matches the condition.
every(callback) Returns true if all items match the condition.
Looping and Transforming
Function Description
forEach(callback) Executes a function for each item.
map(callback) Returns a new array after transforming each item.
filter(callback) Returns a new array with only matching items.
reduce(callback, initialValue) Reduces the array to a single value.
reduceRight(callback, initialValue)
Same as reduce but from right to left.
flat(depth) Flattens nested arrays up to the specified depth.
flatMap(callback) Maps and flattens results one level deep.
Sorting and Combining
Function Description
sort(compareFn) Sorts the array (default is lexicographic).
reverse() Reverses the array in-place.
concat(array2) Combines two or more arrays.
join(separator) Joins all elements into a string.
Other Useful Methods
Function Description
fill(value, start, end) Fills elements with a static value.
copyWithin(target, start, end) Copies part of array to another location.
toString() Converts the array to a string.
entries() Returns an iterator with key/value pairs.
keys() Returns an iterator with the keys (indexes).
values() Returns an iterator with the values.