JavaScript Array Methods

Interactive reference for all JS array methods with live editable code examples. Edit, run, and learn.

0uses
0/10(0)

Adding & Removing

Methods that add or remove elements

push()Adds elements to the end
MutatesReturns: New length
arr.push(...items)
pop()Removes the last element
MutatesReturns: Removed element
arr.pop()
unshift()Adds elements to the beginning
MutatesReturns: New length
arr.unshift(...items)
shift()Removes the first element
MutatesReturns: Removed element
arr.shift()
splice()Adds/removes elements at any position
MutatesReturns: Array of removed
arr.splice(start, deleteCount, ...items)

Transformation

Methods that create new transformed arrays

map()Creates a new array by transforming each element
Non-mutatingReturns: New array
arr.map(callback(item, index, arr))
filter()Creates a new array with elements that pass a test
Non-mutatingReturns: New array
arr.filter(callback(item, index, arr))
reduce()Reduces array to single value by accumulating
Non-mutatingReturns: Accumulated value
arr.reduce(callback(acc, item, index, arr), initialValue)
flat()Flattens nested arrays to specified depth
Non-mutatingReturns: New array
arr.flat(depth)
flatMap()Maps then flattens one level deep
Non-mutatingReturns: New array
arr.flatMap(callback)
slice()Returns a shallow copy of a portion
Non-mutatingReturns: New array
arr.slice(start, end)
concat()Merges arrays together
Non-mutatingReturns: New array
arr.concat(...arrays)

Search & Test

Methods for finding elements and testing conditions

find()Returns first element that passes a test
Non-mutatingReturns: Element or undefined
arr.find(callback(item, index, arr))
findIndex()Returns index of first matching element
Non-mutatingReturns: Index or -1
arr.findIndex(callback)
indexOf()Returns first index of an element
Non-mutatingReturns: Index or -1
arr.indexOf(item, fromIndex)
includes()Checks if array contains an element
Non-mutatingReturns: Boolean
arr.includes(item, fromIndex)
every()Tests if ALL elements pass
Non-mutatingReturns: Boolean
arr.every(callback)
some()Tests if ANY element passes
Non-mutatingReturns: Boolean
arr.some(callback)

Sorting & Ordering

Methods that change element order

sort()Sorts elements in place
MutatesReturns: Sorted array
arr.sort(compareFn)
reverse()Reverses order of elements in place
MutatesReturns: Reversed array
arr.reverse()
toSorted()Returns a new sorted array (non-mutating)
Non-mutatingReturns: New sorted array
arr.toSorted(compareFn)
toReversed()Returns a new reversed array (non-mutating)
Non-mutatingReturns: New reversed array
arr.toReversed()

Iteration

Methods for looping over elements

forEach()Calls a function for each element (no return value)
Non-mutatingReturns: undefined
arr.forEach(callback(item, index, arr))
entries()Returns iterator of [index, value] pairs
Non-mutatingReturns: Iterator
arr.entries()
keys()Returns iterator of indices
Non-mutatingReturns: Iterator
arr.keys()
values()Returns iterator of values
Non-mutatingReturns: Iterator
arr.values()

Conversion

Methods that convert arrays to other types

join()Joins elements into a string
Non-mutatingReturns: String
arr.join(separator)
toString()Converts array to comma-separated string
Non-mutatingReturns: String
arr.toString()
Array.from()Creates array from iterable or array-like
Non-mutatingReturns: New array
Array.from(iterable, mapFn)
Array.isArray()Checks if value is an array
Non-mutatingReturns: Boolean
Array.isArray(value)

Other

Additional useful methods

fill()Fills elements with a static value
MutatesReturns: Modified array
arr.fill(value, start, end)
copyWithin()Copies part of array to another location in same array
MutatesReturns: Modified array
arr.copyWithin(target, start, end)
with()Returns new array with element replaced at index
Non-mutatingReturns: New array
arr.with(index, value)
at()Returns element at index (supports negative)
Non-mutatingReturns: Element
arr.at(index)

Disclaimer:This tool is provided β€œas is” for informational and educational purposes only. Results may not be 100% accurate. ToolBird makes no warranties, express or implied, regarding the accuracy, reliability, or completeness of any output generated by this tool. This tool does not constitute professional, legal, financial, medical, or tax advice. Always consult a qualified professional for important decisions. By using this tool, you agree that ToolBird and its operators shall not be held liable for any damages, losses, or consequences arising from the use of this tool or reliance on its results. All processing occurs in your browser β€” we do not store, transmit, or access your data. Use at your own risk.